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

include_once(AMINA_PATH.'/lib/view.lib.php');

// Star & Tag
$rtag = amina_array_tag($view['wr_7']);

// Auto Move
if ($amina['move'] && $amina['move_bo'] && !$view['is_notice']) {

	$is_auto_move = false;

	if (!$amina['move_term'] || $amina['move_term'] > (G4_SERVER_TIME - strtotime($write['wr_datetime']))/(60*60*24)) {

		if ($amina['move_hit'] && $amina['move_hit'] <= $write['wr_hit']) { //hit
			$is_auto_move = true;
		} else if ($amina['move_cmt'] && $amina['move_cmt'] <= $write['wr_comment']) { //comment
			$is_auto_move = true;
		} else if (!$amina['move_good'] && $amina['move_cnt'] && $amina['move_cnt'] <= $write['wr_good']) { //good
			$is_auto_move = true;
		} else if ($amina['move_good'] == "1" && $amina['move_cnt'] && $amina['move_cnt'] <= $write['wr_nogood']) { //nogood
			$is_auto_move = true;
		} else if ($amina['move_good'] == "2" && $amina['move_cnt'] && $amina['move_cnt'] <= ($write['wr_good'] - $write['wr_nogood'])) { //good - nogood
			$is_auto_move = true;
		} else if ($amina['move_good'] == "3" && $amina['move_cnt'] && $amina['move_cnt'] <= ($write['wr_nogood'] - $write['wr_good'])) { //nogood - good
			$is_auto_move = true;
		} else if ($amina['move_star'] && $amina['move_score']) { //star
			if(!$rtag['people']) $rtag['people'] = 0;
			$move_score = 0;
			if($rtag['people'] > 0) $move_score = $rtag['score'] / $rtag['people'];
			$move_score = round($move_score,2);
			if($rtag['people'] >= $amina['move_star'] && $move_score >= $amina['move_score']) $is_auto_move = true;
		}

		if($is_auto_move) {
			amina_move($board, $wr_id, $amina['move_bo'], $amina['move_ca'], "move");
		}
    }
}

//Deco View
$is_deco_view = ($amina['deco_view'] && $amina['deco_view'] != 'none') ? true : false;

//주소
$lurl = G4_BBS_URL.'/board.php?bo_table='.$bo_table.'&wr_id='.$wr_id; //긴 주소
$surl = amina_short_url($lurl); //짧은 주소
$wr_address = $surl ? $surl : $lurl;

//워터마크
if($amina['wm']) {
	$board['water_mark'][0]['filename'] = G4_PATH.'/'.$amina['wm_file'];
	$board['water_mark'][0]['location'] = $amina['wm_loc'];
	$board['water_mark'][0]['x'] = $amina['wm_x'];
	$board['water_mark'][0]['y'] = $amina['wm_y'];
}

//불당리사이즈 사용
$board['no_view_resize'] = $amina['resize'] ? true : false;

//글옵션 & 아이콘
$wr_post = amina_array_write($view['wr_10']);
$v_icon = amina_array_icon($view['wr_5']);

//1:1 게시판용 체크
if($amina['bo_type'] == "2" && !$is_admin) include_once(AMINA_PATH.'/view.check.1vs1.php');

//열람/다운포인트
$is_po_view = $is_po_down = '';
if($amina['po_view'] || $amina['po_down']) include_once(AMINA_PATH.'/view.check.point.php');

$view['use_po_view'] = $is_po_view;
$view['use_po_down'] = $is_po_down;
$view['msg_po_view'] = $po_view_txt;
$view['msg_po_down'] = $po_down_txt;

//글제목
$view['blind'] = '';
if($view['wr_9'] == "lock" || $view['wr_9'] == "shingo") {
	$view['subject'] = '<img src="'.AMINA_URL.'/img/shingo.gif" alt="" /> 블라인드 처리된 글입니다.';
	if($is_admin) $view['subject'] .= '[ '.cut_hangul_last(get_text($view['wr_subject'])).' ]';
	$view['blind'] = '<p class="view_blind"><span class="icon_lock">블라인드 처리된 글입니다.</span></p>';
} else {
	$view['subject'] = cut_hangul_last(get_text($view['wr_subject']));
	if($wr_post['subj_s']) $view['subject'] = '<del>'.$view['subject'].'</del>';
	if($wr_post['subj_b']) $view['subject'] = '<b>'.$view['subject'].'</b>';
	if($wr_post['subj_i']) $view['subject'] = '<i>'.$view['subject'].'</i>';
	if($wr_post['subj_color']) $view['subject'] = '<span style="color:'.$wr_post['subj_color'].';">'.$view['subject'].'</span>';
}

//회원사진
$view['mb_photo'] = '';
if($amina['view_photo']) { 
	switch($amina['view_photo']) {
		case '1'	:	$view['mb_photo'] = mb_photo($member['mb_id'], $view['mb_id']); break;
		case '2'	:	$view['mb_photo'] = mb_photo($member['mb_id'], $view['mb_id'], '', '', 'is'); break;
		case '3'	: 	if($v_icon['post_icon_mb']) {
							$view['mb_photo'] = mb_photo($member['mb_id'], $view['mb_id'], '', '', 'is');
							if($view['mb_photo']) break;
						}
						if(!$view['mb_photo'] && !file_exists($emo_skin_path.'/'.$v_icon['post_icon'].'.gif')) $v_icon['post_icon'] = rand(1, $amina['emo_cnt']);
						$view['mb_photo'] = '<img src="'.$emo_skin_url.'/'.$v_icon['post_icon'].'.gif" alt="" />'."\n";
						break;
		default		:	$view['mb_photo'] = ''; break;
	}		
}	

//모바일 아이콘
$view['icon_mobile'] = $v_icon['mobile'] ? '<img src="'.AMINA_URL.'/img/icon_mobile.gif" alt="" />' : '';

//XP 아이콘
$view['icon_level'] = $xp['xp_use'] ? xp_icon($view['mb_id'], $v_icon['level']) : '';

//채택
if($amina['cmt_choice'] && $v_icon['choice_point'] > 0) {
	$is_choice = 'none';
	if($v_icon['choice']) $is_choice = 'done';
	if($is_choice != "done" && ($member['mb_id'] == $view['mb_id'])) $is_choice = 'select';
}
$view['choice'] = $is_choice;

//Attach
$view['attach_skin'] = ($amina['attach_skin'] && $amina['attach_skin'] != 'none') ? amina_attach_skin($amina['attach_skin'], $bo_table, $wr_id, $view) : '';

//글내용
if(!$view['blind'] && $view['use_po_view'] == 'new') { //Preview
	$view['content'] = amina_preview_skin($amina['preview_skin'], $bo_table, $wr_id, $view, $view['msg_view_txt']);
} else {
	if($is_admin || (!$view['blind'] && $view['use_po_view'] != 'new')) {
		if($wr_post['img_location'] == "insert") $view['content'] = $view['rich_content'];
		$view['content'] = amina_view_contents($view['content'], $view['file'], $view['wr_6'], $wr_post, (int)$board['bo_image_width'], '', $view['wr_2'], $amina['view_code']);
	}
}

//Poll
$view['poll_up'] = $view['poll_up'] = '';
if($wr_post['chk_poll']) {
	if($wr_post['poll_location']) {
		$view['poll_up'] = amina_poll_skin($amina['poll_skin'], $bo_table, $wr_id, $member['mb_id']);
	} else {
		$view['poll_down'] = amina_poll_skin($amina['poll_skin'], $bo_table, $wr_id, $member['mb_id']);
	}
}

//관련글
$view['related_skin'] = ($amina['related_skin'] && $amina['related_skin'] != 'none' && $view['wr_8']) ? amina_related_skin($amina['related_skin'], $view['wr_4'], $view['wr_8']) : '';

//Star
$view['star_skin'] = ($amina['star'] > 1) ? amina_star_skin($amina['star_skin'], $bo_table, $wr_id, $view['wr_7']) : '';

//Good
$view['good_skin'] = ($board['bo_use_good'] || $board['bo_use_nogood']) ? amina_good_skin($amina['view_good'], $bo_table, $wr_id, $view['wr_good'], $view['wr_nogood']) : '';

//Sign
$view['sign_skin'] = ($amina['sign_skin'] && $amina['sign_skin'] != "none" && $is_signature) ? amina_sign_skin($amina['sign_skin'], $bo_table, $wr_id, $view['mb_id'], $view['name'], $signature) : '';

//SNS
$view['icon_sns'] = $sns_img = '';
if(!$view['blind'] && $amina['view_sns'] != "none") { 
	if(!G4_IS_MOBILE) list($sns_img) = amina_thumb_img($view['file'], $view['wr_6'], $view['wr_content'], 1, $view['wr_4'], $view['wr_8'], $view['wr_8']);
	$sns_img = $sns_img ? gnu_url($sns_img, 'sns') : '';
	$view['icon_sns'] = amina_sns('view_sns'.$view['wr_id'], $amina['view_sns'], $view['wr_subject'], $view['wr_content'], $lurl, $surl, $sns_img);
}

//Tag
$view['tag_skin'] = $view['tag'] = '';
if($wr_post['chk_tag'] || $rtag['related_tag']) {
	include_once(AMINA_PATH.'/lib/tag.lib.php');
	if($wr_post['chk_tag']) $view['tag'] = amina_get_tag($bo_table, $wr_id, true);
	if($rtag['related_tag'] && $amina['tag_skin'] && $amina['tag_skin'] != "none") $view['tag_skin'] = amina_tag_skin($amina['tag_skin'], $bo_table, $wr_id, $rtag['tag_sop'], $rtag['related_tag']);
}

//CSS Load
include_once(AMINA_PATH.'/css.php');

//Syntaxhighlighter
if($amina['view_code']) include_once(AMINA_PATH.'/syntaxhighlighter.php');

//Link Change
if($copy_href || $move_href) {
	$copy_href = str_replace("./move", AMINA_URL."/move", $copy_href);
	$move_href = str_replace("./move", AMINA_URL."/move", $move_href);
}

//href
$print_href = AMINA_URL.'/print.php?bo_table='.$bo_table.'&wr_id='.$wr_id;
$shingo_href = ($amina['shingo'] > 0) ? 'javascript:amina_shingo(\''.AMINA_URL.'/blind.php?bo_table='.$bo_table.'&wr_id='.$wr_id.'\',\'shingo\');' : '';

?>

<link rel="stylesheet" href="<?php echo $view_skin_url.'/'.$amina['view_css']; ?>.css">

<div id="bo_view_wrap" class="deco-view">
<?php
	if($is_deco_view) {
		echo '<link rel="stylesheet" href="'.AMINA_URL.'/skin/deco/view/'.$amina['deco_view'].'.css" />'."\n";
		echo '<div class="deco-view-head-back"><div class="deco-view-head-front"><div class="deco-view-head"></div></div></div>'."\n";
		echo '<div class="deco-view-body-back"><div class="deco-view-body-front">'."\n";
	}
?>
<div id="bo_v">

<?php 
	if($board['is_print'] && file_exists($view_skin_path.'/view.print.php')) {
		include($view_skin_path.'/view.print.php'); 
	} else {
		if(G4_IS_MOBILE && file_exists($view_skin_path.'/m.view.skin.php')) {
			include($view_skin_path.'/m.view.skin.php'); 
		} else {
			include($view_skin_path.'/view.skin.php'); 
		}
	}
?>

</div>
<?php if($is_admin) { //관리자 전용기능 ?>
	<div class="view-admin-ui">
		<ul class="bar11c">
			<li class="first"><a href="javascript:amina_stats('<?php echo $bo_table; ?>','<?php echo $wr_id; ?>');">게시물 회원통계</a></li>
			<li><a href="javascript:amina_shingo('<?php echo AMINA_URL; ?>/blind.php?bo_table=<?php echo $bo_table; ?>&wr_id=<?php echo $wr_id; ?>&act=lock','lock');">블라인드 처리</a></li>
			<li class="last"><a href="javascript:amina_shingo('<?php echo AMINA_URL; ?>/blind.php?bo_table=<?php echo $bo_table; ?>&wr_id=<?php echo $wr_id; ?>&act=unlock','unlock');">블라인드 해제</a></li>
		</ul>
	</div>
<?php } ?>
<?php if(!$frame && !G4_IS_MOBILE && $amina['linked_tab'] && $amina['linked_skin'] && $amina['linked_skin'] != 'none') { ?>
	<aside id="bo_v_linked">
	<?php  // 연동탭 정리
		$linked = amina_array_linked($amina['linked_tab']);
		$linked_cnt = count($linked);
		$linked_skin_path = AMINA_PATH.'/skin/linked/'.$amina['linked_skin'];
		$linked_skin_url = AMINA_URL.'/skin/linked/'.$amina['linked_skin'];
		include($linked_skin_path.'/linked.skin.php'); 
	?>
	<div id="iframe_top"></div>
	<div id="LinkedContent1">
		<?php if($amina['cmt_skin'] != "none") include_once('./view_comment.php'); ?>
	</div>
	<div id="LinkedContent2" style="display:none;">
		<iframe name="LinkedFrame" id="LinkedFrame" width="100%" height="100%" scrolling="no"></iframe>
		<table id="LinkedTbl">
		<tr>
		<td onclick="amina_iframe('LinkedFrame','down');"><span class="down">펼침</span></td>
		<td onclick="amina_iframe('LinkedFrame','up');"><span class="up">접기</span></td>
		</tr>
		</table>
	</div>
	</aside>
<?php } else { if($amina['cmt_skin'] != "none") include_once('./view_comment.php'); } ?>

<nav id="bo_v_bot">
	<div id="amina-view-ui" class="view-btn<? if(!$board['bo_use_list_view']) echo " view-btn-line";?>">
		<ul>
		<?php
		if ($write_href) echo '<li><a href="'.$write_href.$frame_opt.'&sca='.urlencode($sca).'" class="abtn view_write" title="글쓰기"><b>글쓰기</b><em>Write</em></a></li>'."\n";
		if ($reply_href) echo '<li><a href="'.$reply_href.'" class="abtn view_reply" title="답변"><b>답변</b><em>Reply</em></a></li>'."\n";
		if ($search_href) echo '<li><a href="'.$search_href.$frame_opt.'" class="abtn view_list_search" title="검색목록"><b>검색목록</b><em>Search List</em></a></li>'."\n";
		echo '<li><a href="'.$list_href.$frame_opt.'" class="abtn view_list" title="목록"><b>목록</b><em>List</em></a></li>'."\n";
		if(AMINA == "g4s") {
			if ($move_href) echo '<li><a href="'.$move_href.'" onclick="board_move(this.href); return false;" class="abtn view_move" title="글이동"><b>이동</b><em>Move</em></a></li>'."\n";
			if ($copy_href) echo '<li><a href="'.$copy_href.'" onclick="board_move(this.href); return false;" class="abtn view_copy" title="글복사"><b>복사</b><em>Copy</em></a></li>'."\n";
			if ($delete_href) echo '<li><a href="'.$delete_href.'" onclick="del(this.href); return false;" class="abtn view_delete" title="글삭제"><b>삭제</b><em>Delete</em></a></li>'."\n";
		} else {
			if ($move_href) echo '<li><a href="'.$move_href.'" class="abtn view_move" title="글이동"><b>이동</b><em>Move</em></a></li>'."\n";
			if ($copy_href) echo '<li><a href="'.$copy_href.'" class="abtn view_copy" title="글복사"><b>복사</b><em>Copy</em></a></li>'."\n";
			if ($delete_href) echo '<li><a href="'.$delete_href.'" class="abtn view_delete" title="글삭제"><b>삭제</b><em>Delete</em></a></li>'."\n";
		}
		if ($update_href) echo '<li><a href="'.$update_href.'" class="abtn view_modify" title="글수정"><b>수정</b><em>Modify</em></a></li>'."\n";
		if ($prev_href) echo '<li class="left"><a href="'.$prev_href.'" title="'.$prev_wr_subject.'" class="abtn view_prev"><b>이전글</b><em>Prev</em></a></li>'."\n";
		if ($next_href) echo '<li class="left"><a href="'.$next_href.'" title="'.$next_wr_subject.'" class="abtn view_next"><b>다음글</b><em>Next</em></a></li>'."\n";
		?>
		</ul>
		<div class="clear"></div>
	</div>
</nav>
<?php
	if($is_deco_view) {
		echo '</div></div>'."\n";
		echo '<div class="deco-view-tail-back"><div class="deco-view-tail-front"><div class="deco-view-tail"></div></div></div>'."\n";
	}
?>
</div>

<script>
	function clipboard_address(str) {
		prompt("이 글의 고유주소입니다. Ctrl+C를 눌러 복사하거나 확인을 눌러 주세요.", str);
		window.clipboardData.setData("Text",str);
	}

	function file_download(link, file) {
		<?php if ($member['mb_id'] && $board['bo_download_point'] < 0) { ?>if (confirm("'"+file+"' 파일을 다운로드 하시면 기본 다운포인트가 차감(<?php echo number_format($board['bo_download_point']); ?>점)됩니다.\n\n기본 다운포인트는 게시물당 한번만 차감되며 다음에 다시 다운로드 하셔도 중복하여 차감하지 않습니다.\n\n그래도 다운로드 하시겠습니까?"))<?php } ?>
	    document.location.href=link;
	}
	<?php if(AMINA == "g4s") { ?>
		function board_move(href) {
		    window.open(href, "boardmove", "left=50, top=50, width=500, height=550, scrollbars=1");
		}
	<?php } ?>
</script>
