<?php
include_once('./_common.php');

if (isset($_REQUEST['iq_id'])) { 
    $iq_id = (int)$_REQUEST['iq_id'];
}

if (!$iq_id) {
	alert('iq_id 값이 넘어오지 않았습니다.', G5_URL);
}

$view = sql_fetch(" select * from `{$g5['g5_shop_item_qa_table']}` a join `{$g5['g5_shop_item_table']}` b on (a.it_id=b.it_id) where a.iq_id = '$iq_id' ");

if(!$view['iq_id']) {
	alert('존재하지 않는 자료입니다.', G5_URL);
}

if($view['iq_secret']) {
	if($is_admin || ($view['mb_id'] && $member['mb_id' ] == $view['mb_id'])) {
		;
	} else {
		alert('비밀글로 보호된 문의입니다.');
	}
} 

if($ca_id) {
	$qstr .= '&amp;ca_id='.$ca_id;
}

// 버튼
$view['iq_ans_href'] = $view['iq_edit_href'] = $view['iq_del_href'] = '';

if($is_admin || ($view['pt_id'] && $member['mb_id'] == $view['pt_id'])) {
	$view['iq_ans_href'] = './itemqansform.php?it_id='.$view['it_id'].'&amp;iq_id='.$iq_id.'&amp;page='.$page.'&amp;move=3';
}

if($is_admin || ($view['mb_id'] && $member['mb_id'] == $view['mb_id'])) {
	$view['iq_edit_href'] = './itemqaform.php?it_id='.$view['it_id'].'&amp;iq_id='.$iq_id.'&amp;page='.$page.'&amp;w=u&amp;move=3';

	$hash = md5($view['iq_id'].$view['iq_time'].$view['iq_ip']);
	$view['iq_del_href'] = './itemqaformupdate.php?it_id='.$view['it_id'].'&amp;iq_id='.$iq_id.'&amp;w=d&amp;move=2&amp;hash='.$hash;
}

$view['iq_time'] = strtotime($view['iq_time']);
$view['iq_photo'] = apms_photo_url($view['mb_id']);
$view['iqa_photo'] = ($view['pt_id']) ? apms_photo_url($view['pt_id']) : apms_photo_url($config['cf_admin']);
$view['iq_question'] = apms_content(conv_content($view['iq_question'], 1));
$view['iq_answer'] = apms_content(conv_content($view['iq_answer'], 1));
$view['it_href'] = './item.php?it_id='.$view['it_id'];

// Page ID
$pid = ($pid) ? $pid : 'iqa';
$at = apms_page_thema($pid);
if(!defined('THEMA_PATH')) {
	include_once(G5_LIB_PATH.'/apms.thema.lib.php');
}

$skin_row = array();
$skin_row = apms_rows('qa_'.MOBILE_.'rows, qa_'.MOBILE_.'skin, qa_'.MOBILE_.'set');
$skin_path = G5_SKIN_PATH.'/apms/qa/'.$skin_row['qa_'.MOBILE_.'skin'];
$skin_url = G5_SKIN_URL.'/apms/qa/'.$skin_row['qa_'.MOBILE_.'skin'];

// 셋업
$setup_href = '';
if ($is_demo || $is_admin == 'super') {
	$setup_href = './skin.setup.php?skin=qa';
}

// SEO 메타태그
$seo_title = htmlspecialchars(apms_get_text($view['iq_subject']).' < '.$view['it_name'].' < '.$config['cf_title']);
$seo_subject = htmlspecialchars(apms_get_text($view['iq_subject']));
$seo_desc = htmlspecialchars(apms_cut_text($view['iq_content'], 200));
$seo_publisher = htmlspecialchars(apms_get_text($config['cf_title']));
$seo_creator = htmlspecialchars(apms_get_text($view['iq_name']));
$seo_keyword = apms_seo_keyword($view['pt_tag']);
$seo_url = G5_SHOP_URL.'/itemuseview.php?is_id='.$is_id;
$seo_img = apms_it_write_thumbnail($view['it_id'], $view['iq_content'], 0, 0);

$metatag = PHP_EOL.'<meta name="title" content="'.$seo_title.'" />';
$metatag .= PHP_EOL.'<meta name="subject" content="'.$seo_subject.'" />';
$metatag .= PHP_EOL.'<meta name="publisher" content="'.$seo_publisher.'" />';
$metatag .= PHP_EOL.'<meta name="author" content="'.$seo_creator.'" />';
$metatag .= PHP_EOL.'<meta name="robots" content="index,follow" />';
if($seo_keyword) {
	$seo_keyword = htmlspecialchars(apms_get_text($seo_keyword));
	$metatag .= PHP_EOL.'<meta name="keywords" content="'.$seo_keyword.'" />';
}
$metatag .= PHP_EOL.'<meta name="description" content="'.$seo_desc.'" />';
$metatag .= PHP_EOL.'<meta property="og:title" content="'.$seo_title.'"/>';
$metatag .= PHP_EOL.'<meta property="og:site_name" content="'.$seo_publisher.'"/>';
$metatag .= PHP_EOL.'<meta property="og:author" content="'.$seo_creator.'" />';
$metatag .= PHP_EOL.'<meta property="og:url" content="'.$seo_url.'"/>';
$metatag .= PHP_EOL.'<meta property="og:description" content="'.$seo_desc.'"/>';
if($seo_img['src']) {
	$metatag .= PHP_EOL.'<meta property="og:image" content="'.$seo_img['src'].'"/>';
}

add_metatag($metatag, 0);

$g5['title'] = '문의보기';
include_once('./_head.php');

$wset = array();
if($skin_row['qa_'.MOBILE_.'set']) {
	$wset = apms_unpack($skin_row['qa_'.MOBILE_.'set']);
}

include_once($skin_path.'/qaview.skin.php');
include_once('./_tail.php');
?>
