<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가 
include("$g4[path]/gnu_lib/menu.php");
include("$board_skin_path/simple_html_dom.php");
include_once("$board_skin_path/skin.lib.php");

if (!function_exists("imagecopyresampled")) alert("GD 2.0.1 이상 버전이 설치되어 있어야 사용할 수 있는 갤러리 게시판 입니다.");

if (!$board[bo_1]) {
    $board[bo_1] = "360";
    $sql = " update $g4[board_table] set bo_1 = '$board[bo_1]', bo_1_subj = '목록 가로 픽셀' where bo_table = '$bo_table' ";
    sql_query($sql);
}

if (!$board[bo_2]) {
    $board[bo_2] = "480";
    $sql = " update $g4[board_table] set bo_2 = '$board[bo_2]', bo_2_subj = '목록 세로 픽셀' where bo_table = '$bo_table' ";
    sql_query($sql);
}

$mod = $board[bo_gallery_cols];
$td_width = (int)(100 / $mod);
?>
<div style="height:12px; line-height:1px; font-size:1px;">&nbsp;</div>

<!-- 게시글 보기 시작 -->
<table width="<?=$width?>" align="center" cellpadding="0" cellspacing="0"><tr><td>


<div style="clear:both; height:30px;">
    <div style="float:left; margin-top:6px;">
    <img src="<?=$board_skin_path?>/img/icon_date.gif" align=absmiddle border='0'>
    <span style="color:#888888;">등록일 : <?=date("y-m-d H:i", strtotime($view[wr_datetime]))?></span>
    </div>

    <!-- 링크 버튼 -->
    <div style="float:right;">
    <? 
    ob_start(); 
    ?>
  
    <? if ($search_href) { echo "<a href=\"$search_href\"><img src='$board_skin_path/img/btn_list_search.gif' border='0' align='absmiddle'></a> "; } ?>
    <? echo "<a href=\"$list_href\"><img src='$board_skin_path/img/btn_list.gif' border='0' align='absmiddle'></a> "; ?>
    
    <?
    $link_buttons = ob_get_contents();
    ob_end_flush();
    ?>
    </div>
</div>

<div style="border:1px solid #ddd; clear:both; height:34px; background:url(<?=$board_skin_path?>/img/title_bg.gif) repeat-x;">
    <table border=0 cellpadding=0 cellspacing=0 width=100%>
    <tr>
        <td style="padding:8px 0 0 10px;">
            <div style="color:#505050; font-size:13px; font-weight:bold; word-break:break-all;">
            <? if ($is_category) { echo ($category_name ? "[$view[ca_name]] " : ""); } ?>
            <?=cut_hangul_last(get_text($view[wr_subject]))?>      (<?=$view[wr_1]?>)
            </div>
        </td>
        <td align="right" style="padding:6px 6px 0 0;" width=120>
           
        </td>
    </tr>
    </table>
</div>
<div style="height:3px; background:url(<?=$board_skin_path?>/img/title_shadow.gif) repeat-x; line-height:1px; font-size:1px;"></div>


<table border=0 cellpadding=0 cellspacing=0 width=<?=$width?>>

<?
// 가변 파일
$cnt = 0;
for ($i=0; $i<count($view[file]); $i++) {
    if ($view[file][$i][source] && !$view[file][$i][view]) {
        $cnt++;
        echo "<tr><td height=30 background=\"$board_skin_path/img/view_dot.gif\">";
        echo "&nbsp;&nbsp;<img src='{$board_skin_path}/img/icon_file.gif' align=absmiddle border='0'>";
        echo "<a href=\"javascript:file_download('{$view[file][$i][href]}', '".urlencode($view[file][$i][source])."');\" title='{$view[file][$i][content]}'>";
        echo "&nbsp;<span style=\"color:#888;\">{$view[file][$i][source]} ({$view[file][$i][size]})</span>";
        echo "&nbsp;<span style=\"color:#ff6600; font-size:11px;\">[{$view[file][$i][download]}]</span>";
        echo "&nbsp;<span style=\"color:#d3d3d3; font-size:11px;\">DATE : {$view[file][$i][datetime]}</span>";
        echo "</a></td></tr>";
    }
}

// 링크
$cnt = 0;
for ($i=1; $i<=$g4[link_count]; $i++) {
    if ($view[link][$i]) {
        $cnt++;
        $link = cut_str($view[link][$i], 70);
        echo "<tr><td height=30 background=\"$board_skin_path/img/view_dot.gif\">";
        echo "&nbsp;&nbsp;<img src='{$board_skin_path}/img/icon_link.gif' align=absmiddle border='0'>";
        echo "<a href='{$view[link_href][$i]}' target=_blank>";
        echo "&nbsp;<span style=\"color:#888;\">{$link}</span>";
        echo "&nbsp;<span style=\"color:#ff6600; font-size:11px;\">[{$view[link_hit][$i]}]</span>";
        echo "</a></td></tr>";
    }
}
?>
<tr> 
    <td height="150" style="word-break:break-all; padding:10px;"><table>
    <tr>
		<td width=30% valign=top>
	 <? 
        // 파일 출력
				        for ($i=0; $i < 1; $i++) {

//썸네일 코드 시작
							$data_path = $g4['path'] . "/data/file/{$bo_table}";//라이브러리 파일 참조
							$thumb_path = $data_path . '/thumbView';

							$view_w = 360; //썸네일 가로사이즈
							$view_h = 480; //썸네일 세로사이즈
							$sch_q = 120; //썸네일 퀼리티

							if (!is_dir($thumb_path)) {
							@mkdir($thumb_path, 0707);
							@chmod($thumb_path, 0707);
							}
						    $filename = $view[file][0][file]; //파일명
						    $thumb = $thumb_path.'/'.$filename; //썸네일
						    if (!file_exists($thumb))
						    {
								$file = $data_path.'/'.$filename; //원본
						        if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file) && file_exists($file))
						        {
						            $size = getimagesize($file);
						            if ($size[2] == 1) $src = imagecreatefromgif($file);
						            else if ($size[2] == 2) $src = imagecreatefromjpeg($file);
						            else if ($size[2] == 3) $src = imagecreatefrompng($file);
						            else
						            continue;

						            $rate = $view_w / $size[0];
						            $height = (int)($size[1] * $rate);

						            if ($height < $view_h)
						                $dst = imagecreatetruecolor($view_w, $height);
						            else
						                $dst = imagecreatetruecolor($view_w, $view_h);
							            imagecopyresampled($dst, $src, 0, 0, 0, 0, $view_w, $height, $size[0], $size[1]);
							            imagejpeg($dst, $thumb_path.'/'.$filename, $sch_q);
							            chmod($thumb_path.'/'.$filename, 0707);
						        }
						    }

						    if (file_exists($thumb) && $filename) {
								echo "<img src='$thumb' style='border:1px solid #E2E2E2;'>";
						    }	
				}
 ?>
 <?// Create DOM from URL or file

 $site = "http://www.aladin.co.kr/shop/wproduct.aspx?ISBN=$view[wr_7]";
 // echo $site;
$html = file_get_html($site);

// Find all images 
$cover_img = trim($view[wr_7]);
$cover_img = preg_replace("/\s+/","",$cover_img);
foreach($html->find('img') as $element) {
//	echo $cover_img;
	$result = strstr($element->src, $cover_img);
//	echo $result;
	if($result) echo "<img src='".$element->src."'><br>";
	//  echo $element->src."<br>";
}
?></td>
		<td> <!-- 내용 출력 -->


        <table>
	   <tr>
		
		<td width=30></td>
		<td valign=top><span id="writeContents"><?=$view[content];?></span></td>
	   </tr>
	   </table>

       </td>
    </tr>
    </table>
        

       

</td>
</tr>
<? if ($is_signature) { echo "<tr><td align='center' style='border-bottom:1px solid #E7E7E7; padding:5px 0;'>$signature</td></tr>"; } // 서명 출력 ?>
</table>
<br>

<?
// 코멘트 입출력
 if ($member[mb_id] && ($is_admin == "super" || $is_admin == "group" || $is_admin == "board")) include_once("./view_comment.php");
?>

<div style="height:1px; line-height:1px; font-size:1px; background-color:#ddd; clear:both;">&nbsp;</div>

<div style="clear:both; height:43px;">
    <div style="float:left; margin-top:10px;">
    <? if ($prev_href) { echo "<a href=\"$prev_href\" title=\"$prev_wr_subject\"><img src='$board_skin_path/img/btn_prev.gif' border='0' align='absmiddle'></a>&nbsp;"; } ?>
    <? if ($next_href) { echo "<a href=\"$next_href\" title=\"$next_wr_subject\"><img src='$board_skin_path/img/btn_next.gif' border='0' align='absmiddle'></a>&nbsp;"; } ?>
    </div>

    <!-- 링크 버튼 -->
    <div style="float:right; margin-top:10px;">
    <?=$link_buttons?>
    </div>
</div>

<div style="height:2px; line-height:1px; font-size:1px; background-color:#dedede; clear:both;">&nbsp;</div>

</td></tr></table><br>

<script type="text/javascript">
function file_download(link, file) {
    <? if ($board[bo_download_point] < 0) { ?>if (confirm("'"+decodeURIComponent(file)+"' 파일을 다운로드 하시면 포인트가 차감(<?=number_format($board[bo_download_point])?>점)됩니다.\n\n포인트는 게시물당 한번만 차감되며 다음에 다시 다운로드 하셔도 중복하여 차감하지 않습니다.\n\n그래도 다운로드 하시겠습니까?"))<?}?>
    document.location.href=link;
}
</script>

<script type="text/javascript" src="<?="$g4[path]/js/board.js"?>"></script>
<script type="text/javascript">
window.onload=function() {
    resizeBoardImage(<?=(int)$board[bo_image_width]?>);
    drawFont();
}
</script>
<!-- 게시글 보기 끝 -->
