<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');
include_once($board_skin_path.'/board.lib.php');
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.css">', 0);
add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/lite-yt-embed.css">', 0);
add_javascript('<script src="'.$board_skin_url.'/lite-yt-embed.js"></script>', 3);

$good_member = $nogood_member = array();
$sql = "select * from {$g5['board_good_table']} where bo_table = '{$bo_table}' and wr_id = '{$wr_id}'";
$res = sql_query($sql);
for($i=0;$row=sql_fetch_array($res);$i++) {
    if($row['bg_flag'] == 'good') {
        $good_member[] = $row['mb_id'];
    } else {
        $nogood_member[] = $row['mb_id'];
    }
}
?>

<script src="<?php echo G5_JS_URL; ?>/viewimageresize.js"></script>

<!-- 게시물 읽기 시작 { -->
<div id="board-view" class="mobile-padding">
    <div class="view-subject">
        <?php if ($category_name) { ?>
            <h5><span class="view_category"><?php echo $view['ca_name']; // 분류 출력 끝 ?></span></h5>
        <?php } ?>
        <h4><?php echo get_text($view['wr_subject']);?></h4>
    </div>
    <div class="view-info">
        <div class="view-info-photo"><?php echo get_member_profile_img($view['mb_id']) ?></div>
        <div class="view-info-user">
            <span class="sound_only">작성자</span><strong><?php echo $view['name'] ?><?php if ($is_ip_view) { echo "&nbsp;($ip)"; } ?></strong>
            <div class="view-article-info">
                <span class="date"><i class="fa fa-clock-o"></i><?php echo date("y-m-d H:i", strtotime($view['wr_datetime'])) ?></span>
                <span class="hit"><i class="fa fa-eye"></i><?php echo number_format($view['wr_hit']) ?></span>
                <span class="comment"><a href="#comment-list"><i class="fa fa-commenting-o"></i><?php echo number_format($view['wr_cmt_num']) ?></a></span>
                <?php if ($is_good) { ?><span class="good"><i class="fa fa-thumbs-up"></i><?php echo number_format($view['wr_good']) ?></span><?php } ?>
                <?php if ($is_nogood) { ?><span class="nogood"><i class="fa fa-thumbs-down"></i><?php echo number_format($view['wr_nogood']) ?></span><?php } ?>
            </div>
            <div class="view-more"></div>
        </div>
    </div>
    <!-- 관련링크 시작 { -->
    <?php if(isset($view['link']) && array_filter($view['link'])) { ?>
    <div class="view-link">
        <h2 class="sound_only">관련링크</h2>
        <ul>
        <?php
        // 링크
        $cnt = 0;
        for ($i=1; $i<=count($view['link']); $i++) {
            if ($view['link'][$i]) {
                $cnt++;
                $link = cut_str($view['link'][$i], 70);
                echo '<li>';
                echo '<i class="fa fa-link" aria-hidden="true"></i><a href="'.$view['link_href'][$i].'" target="_blank">'.$link.'</a>';
                echo '<span>'.$view['link_hit'][$i].'회 연결</span>';
                echo '</li>';
            }
        }
        ?>
        </ul>
    </div>
    <?php } ?>
    <!-- } 관련링크 끝 -->
    <!-- 첨부파일 시작 { -->
    <?php
    $cnt = 0;
    if ($view['file']['count']) {
        for ($i=0; $i<count($view['file']); $i++) {
            if (isset($view['file'][$i]['source']) && $view['file'][$i]['source'] && !$view['file'][$i]['view']) {
                $cnt++;
            }
        }
    }
    ?>
    <?php if($cnt > 0) { ?>
    <div class="view-file">
        <h2 class="sound_only">첨부파일</h2>
        <ul>
        <?php
        // 가변 파일
        for ($i=0; $i<count($view['file']); $i++) {
            if (isset($view['file'][$i]['source']) && $view['file'][$i]['source'] && !$view['file'][$i]['view']) {
                echo '<li>';
                echo '<i class="fa fa-folder-open" aria-hidden="true"></i>';
                echo '<a href="'.$view['file'][$i]['href'].'" class="view_file_download">'.$view['file'][$i]['source'] . $view['file'][$i]['content'].'('.$view['file'][$i]['size'].')</a>';
                echo '<span class="bo_v_file_cnt">'.$view['file'][$i]['download'].'회 다운로드 | DATE : '.$view['file'][$i]['datetime'].'</span>';
                echo '</li>';
            }
        }
         ?>
        </ul>
    </div>
    <?php } ?>
    <!-- } 첨부파일 끝 -->
    <div class="view-article">
        <!--movie-->
        <?php
        if($view['wr_movie_url']) {
            $movie_id = get_movie_id($view['wr_movie_url']);
            if($movie_id) {
                echo '<div class="view-movie"><lite-youtube videoid="'.$movie_id.'" playlabel=""></lite-youtube></div>';
            }
        }
        ?>
        <!--movie-->
        <?php
        // 파일 출력
        $v_img_count = count($view['file']);
        if($v_img_count) {
            echo '<div class="view-file-image">';
            foreach($view['file'] as $view_file) {
                echo get_file_thumbnail($view_file);
            }
            echo '</div>';
        }
        ?>
        <!-- 본문 내용 시작 { -->
        <div class="view-content"><?php echo get_view_thumbnail($view['content']); ?></div>
        <!-- } 본문 내용 끝 -->
        <?php if ($is_signature) { ?><p><?php echo $signature ?></p><?php } //사용하지 않는 기능?>
        <!--  추천 비추천 시작 { -->
        <?php if ($board['bo_use_good'] || $board['bo_use_nogood']) { ?>
        <div class="view-vote">
            <div class="view-vote-act">
                <?php if ($board['bo_use_good']) { ?>
                    <div class="view-vote-act-gng good">
                        <a href="javascript:void(0);" id="good_button" class="vote-act vote-good" data-flag="good"><i class="fa fa-thumbs-o-up" aria-hidden="true"></i><span class="sound_only">추천</span><strong><?php echo number_format($view['wr_good']) ?></strong></a>
                        <span class="vote_msg"></span>
                    </div>
                <?php } ?>
                <?php if ($board['bo_use_nogood']) { ?>
                    <div class="view-vote-act-gng nogood">
                        <a href="javascript:void(0);" id="nogood_button" class="vote-act vote-nogood" data-flag="nogood"><i class="fa fa-thumbs-o-down" aria-hidden="true"></i><span class="sound_only">비추천</span><strong><?php echo number_format($view['wr_nogood']) ?></strong></a>
                        <span class="vote_msg"></span>
                    </div>
                <?php } ?>
            </div>
            <?php if(!$is_member) { ?>
            <div class="view-vote-login-msg"><i class="fa fa-exclamation-circle"></i>로그인 후 추천 또는 비추천을 하실 수 있습니다.</div>
            <?php } ?>
            <?php if( !empty($good_member) || !empty($nogood_member) ) { ?>
            <div class="view-vote-users-btn"><span class="vote_view">추천/비추천 회원보기</span></div>
            <div class="view-vote-users">
                <div class="vote-users good-users">
                    <h5>이 글을 추천한 회원</h5>
                    <?php if( !empty($good_member) ) { ?>
                    <div class="vote-users-list">
                        <?php
                        foreach($good_member as $k=>$v) {
                            echo '<div class="vote-user-name">'.$v.'</div>';
                        }
                        ?>
                    </div>
                    <?php } ?>
                </div>
                <div class="vote-users nogood-users">
                    <h5>이 글을 비추천한 회원</h5>
                    <?php if( !empty($nogood_member) ) { ?>
                    <div class="vote-users-list">
                        <?php
                        foreach($nogood_member as $k=>$v) {
                            echo '<div class="vote-user-name">'.$v.'</div>';
                        }
                        ?>
                    </div>
                    <?php } ?>
                </div>
            </div>
            <?php } ?>
        </div>
        <?php } ?>
        <!-- }  추천 비추천 끝 -->
    </div>
    <div class="view-btn">
        <div class="view-sns"><?php include_once(G5_SNS_PATH."/view.sns.skin.php"); ?></div>
        <div class="view-user">
            <ul>
                <?php if($copy_href) { ?><li class="mobile-none"><a href="<?php echo $copy_href ?>" class="btn_board btn_board_copy" onclick="board_move(this.href); return false;">복사</a></li><?php } ?>
                <?php if($move_href) { ?><li class="mobile-none"><a href="<?php echo $move_href ?>" class="btn_board btn_board_move" onclick="board_move(this.href); return false;">이동</a></li><?php } ?>
                <?php if ($delete_href) { ?><li><a href="<?php echo $delete_href ?>" class="btn_board btn_board_del" onclick="del(this.href); return false;">삭제</a></li><?php } ?>
                <?php if ($update_href) { ?><li><a href="<?php echo $update_href ?>" class="btn_board btn_board_modify">수정</a></li><?php } ?>
                <?php if ($reply_href) { ?><li><a href="<?php echo $reply_href ?>" class="btn_board btn_board_reply">답변</a></li><?php } ?>
                <?php if ($write_href) { ?><li><a href="<?php echo $write_href ?>" class="btn_board btn_board_write">글쓰기</a></li><?php } ?>
                <li><a href="<?php echo $list_href ?>" class="btn_board btn_board_list">목록</a></li>
            </ul>
        </div>
    </div>
</div>

<?php if ($prev_href || $next_href) { ?>
<div class="view-nb mobile-padding">
    <ul class="bo_v_nb">
        <?php if ($prev_href) { ?><li class="btn_prv"><span class="nb_tit"><i class="fa fa-chevron-up" aria-hidden="true"></i> 이전글</span><a href="<?php echo $prev_href ?>"><?php echo $prev_wr_subject;?></a> <span class="nb_date"><?php echo str_replace('-', '.', substr($prev_wr_date, '2', '8')); ?></span></li><?php } ?>
        <?php if ($next_href) { ?><li class="btn_next"><span class="nb_tit"><i class="fa fa-chevron-down" aria-hidden="true"></i> 다음글</span><a href="<?php echo $next_href ?>"><?php echo $next_wr_subject;?></a>  <span class="nb_date"><?php echo str_replace('-', '.', substr($next_wr_date, '2', '8')); ?></span></li><?php } ?>
    </ul>
</div>
<?php } ?>

<div id="view-comment" class="mobile-padding">
<?php include_once($board_skin_path.'/view_comment.php'); //경로를 스킨으로 변경 ?>
</div>




<script>
<?php if ($board['bo_download_point'] < 0) { ?>
$(function() {
    $("a.view_file_download").click(function() {
        if(!g5_is_member) {
            alert("다운로드 권한이 없습니다.\n회원이시라면 로그인 후 이용해 보십시오.");
            return false;
        }

        var msg = "파일을 다운로드 하시면 포인트가 차감(<?php echo number_format($board['bo_download_point']) ?>점)됩니다.\n\n포인트는 게시물당 한번만 차감되며 다음에 다시 다운로드 하셔도 중복하여 차감하지 않습니다.\n\n그래도 다운로드 하시겠습니까?";

        if(confirm(msg)) {
            var href = $(this).attr("href")+"&js=on";
            $(this).attr("href", href);

            return true;
        } else {
            return false;
        }
    });
});
<?php } ?>

function board_move(href)
{
    window.open(href, "boardmove", "left=50, top=50, width=500, height=550, scrollbars=1");
}
</script>

<script>
$(function() {
    $("a.view_image").click(function() {
        window.open(this.href, "large_image", "location=yes,links=no,toolbar=no,top=10,left=10,width=10,height=10,resizable=yes,scrollbars=no,status=no");
        return false;
    });
    $('.vote_view').click(function() {
        if( $('.view-vote-users').hasClass('open')) {
            $('.view-vote-users').removeClass('open');
        } else {
            $('.view-vote-users').addClass('open');
        }
    });
    // 추천, 비추천
    $('.vote-act').click(function() {
        var $this = $(this),
            mode  = $this.data('flag'),
            table = '<?php echo $bo_table;?>',
            wr_id = '<?php echo $wr_id;?>';
        $.ajax({
            type: "POST",
            data: { act:mode,bo_table:table,wr_id:wr_id },
            url: '<?php echo $board_skin_url;?>/ajax.board.php',
            success: function(data) {
                $this.next('.vote_msg').text(data.message);
                $this.next('.vote_msg').fadeIn(200).delay(2500).fadeOut(200);
                if(data.result == 'success') {
                    $this.find('strong').text(data.count);
                }
            }
        });
        
    });
    // 이미지 리사이즈
    $("#bo_v_atc").viewimageresize();
});
</script>
<!-- } 게시글 읽기 끝 -->