사용후기 상품문의 코드 변경중

This commit is contained in:
gnuboard
2013-06-18 11:02:52 +09:00
parent bd6837e4ab
commit 75418eb7c1
9 changed files with 389 additions and 114 deletions

13
bbs/alert_login.php Normal file
View File

@ -0,0 +1,13 @@
<?php
include_once('./_common.php');
include_once(G4_PATH.'/head.sub.php');
?>
<script>
alert("<?php echo $msg; ?>");
document.location=g4_bbs_url+"/login.php?url=<?php echo $url; ?>";
</script>
<?php
include_once(G4_PATH.'/tail.sub.php');
?>

View File

@ -169,6 +169,21 @@ function alert_close($msg, $error=true)
exit;
}
// 경고메세지 출력후 창을 닫음
function alert_login($msg, $url)
{
global $g4;
$header = '';
if (isset($g4['title'])) {
$header = $g4['title'];
}
include_once(G4_BBS_PATH.'/alert_login.php');
exit;
}
// confirm 창
function confirm($msg, $url1='', $url2='', $url3='')
{

View File

@ -597,9 +597,18 @@ else
<h2>상품문의</h2>
<?php echo pg_anchor('qa'); ?>
<div id="itemqa"></div>
<script>
$(function(){
$("#itemqa").load("./itemqa.php", {it_id:"<?php echo $it_id; ?>"});
});
</script>
<?php
/*
$qa_page_rows = 10; // 페이지당 목록수
include_once('./itemqa.inc.php');
*/
?>
</section>

198
shop/itemqa.php Normal file
View File

@ -0,0 +1,198 @@
<?php
include_once('./_common.php');
include_once(G4_LIB_PATH.'/thumbnail.lib.php');
$it_id = $_REQUEST['it_id'];
$itemqa_list = "./itemqalist.php";
$itemqa_form = "./itemqaform.php?it_id=".$it_id;
$itemqa_formupdate = "./itemqaformupdate.php?it_id=".$it_id;
include_once(G4_PATH.'/head.sub.php');
?>
<section id="sit_qa_list">
<h3>등록된 상품문의</h3>
<?php
$sql_common = " from `{$g4['shop_item_qa_table']}` where it_id = '{$it_id}' ";
// 테이블의 전체 레코드수만 얻음
$sql = " select COUNT(*) as cnt " . $sql_common;
$row = sql_fetch($sql);
$total_count = $row['cnt'];
$rows = 5;
$total_page = ceil($total_count / $rows); // 전체 페이지 계산
if ($page == "") $page = 1; // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 레코드 구함
$sql = "select * $sql_common order by iq_id desc limit $from_record, $rows ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
$iq_num = $total_count - ($page - 1) * $rows - $i;
$iq_star = get_star($row['iq_score']);
$iq_name = get_text($row['iq_name']);
$iq_subject = conv_subject($row['iq_subject'],50,"…");
$iq_question = get_view_thumbnail($row['iq_question'], 300);
$iq_time = substr($row['iq_time'], 2, 8);
$iq_href = './itemqalist.php?bo_table=itemqa&amp;wr_id='.$row['wr_id'];
$hash = md5($row['iq_id'].$row['iq_time'].$row['iq_ip']);
// http://stackoverflow.com/questions/6967081/show-hide-multiple-divs-with-jquery?answertab=votes#tab-top
$iq_stats = '';
$iq_answer = '';
$iq_flag = 0;
if ($row['iq_answer'])
{
$iq_answer = get_view_thumbnail($row['iq_answer'], 300);
$iq_stats = '답변완료';
} else {
$iq_stats = '답변전';
$iq_answer = '답변이 등록되지 않았습니다.';
$iq_flag = 1;
}
if ($i == 0) echo '<ol id="sit_qa_ol">';
?>
<li class="sit_qa_li">
<button type="button" class="sit_qa_li_title" onclick="javascript:qa_menu('sit_qa_con_<?php echo $i; ?>')"><b><?php echo $num; ?>.</b> <?php echo $iq_subject; ?></button>
<dl class="sit_qa_dl">
<dt>작성자</dt>
<dd><?php echo $iq_name; ?></dd>
<dt>작성일</dt>
<dd><?php echo $iq_time; ?></dd>
<dt>상태</dt>
<dd><?php echo $iq_stats; ?></dd>
</dl>
<div id="sit_qa_con_<?php echo $i; ?>" class="sit_qa_con">
<p class="sit_qa_qaq">
<strong>문의내용</strong><br>
<?php echo $iq_question; // 상품 문의 내용 ?>
</p>
<p class="sit_qa_qaa">
<strong>답변</strong><br>
<?php echo $iq_answer; ?>
</p>
<?php if ($row['mb_id'] == $member['mb_id'] && $iq_answer == 0) { ?>
<div class="sit_qa_cmd">
<a href="<?php echo $itemqa_form."&amp;iq_id={$row['iq_id']}&amp;w=u"; ?>" class="itemqa_form" onclick="return false;">수정</a>
<a href="<?php echo $itemqa_formupdate."&amp;iq_id={$row['iq_id']}&amp;w=d&amp;hash={$hash}"; ?>" class="itemqa_delete" onclick="return false;">삭제</a>
<!-- <button type="button" onclick="javascript:itemqa_update(<?php echo $i; ?>);" class="btn01">수정</button>
<button type="button" onclick="javascript:itemqa_delete(fitemqa_password<?php echo $i; ?>, <?php echo $i; ?>);" class="btn01">삭제</button> -->
</div>
<?php } ?>
</div>
</div>
</li>
<li class="sit_qa_li">
<button type="button" class="sit_qa_li_title" onclick="javascript:qa_menu('sit_qa_con_<?php echo $i; ?>')"><b><?php echo $iq_num; ?>.</b> <?php echo $iq_subject; ?></button>
<dl class="sit_qa_dl">
<dt>작성자</dt>
<dd><?php echo $iq_name; ?></dd>
<dt>작성일</dt>
<dd><?php echo $iq_time; ?></dd>
</dl>
<div id="sit_qa_con_<?php echo $i; ?>" class="sit_qa_con">
<p>
<?php echo $iq_question; // 상품문의 질문 ?>
<?php echo $iq_answer; // 상품문의 답변 ?>
<a href="<?php echo $itemqa_form."&amp;iq_id={$row['iq_id']}&amp;w=u"; ?>" class="itemqa_form" onclick="return false;">수정</a>
<a href="<?php echo "./itemqaformupdate.php?w=d&amp;it_id={$row['it_id']}&amp;iq_id={$row['iq_id']}&amp;hash={$hash}"; ?>">삭제</a>
</p>
</div>
</li>
<?php }
if ($i >= 0) echo '</ol>';
if (!$i) echo '<p class="sit_empty">상품문의가 없습니다.</p>';
?>
</section>
<?php
// 현재페이지, 총페이지수, 한페이지에 보여줄 행, URL
function itemqa_page($write_pages, $cur_page, $total_page, $url, $add="")
{
$url = preg_replace('#&amp;page=[0-9]*(&amp;page=)$#', '$1', $url);
$str = '';
if ($cur_page > 1) {
$str .= '<a href="'.$url.'1'.$add.'" class="pg_page pg_start" onclick="return false;">처음</a>'.PHP_EOL;
}
$start_page = ( ( (int)( ($cur_page - 1 ) / $write_pages ) ) * $write_pages ) + 1;
$end_page = $start_page + $write_pages - 1;
if ($end_page >= $total_page) $end_page = $total_page;
if ($start_page > 1) $str .= '<a href="'.$url.($start_page-1).$add.'" class="pg_page pg_prev" onclick="return false;">이전</a>'.PHP_EOL;
if ($total_page > 1) {
for ($k=$start_page;$k<=$end_page;$k++) {
if ($cur_page != $k)
$str .= '<a href="'.$url.$k.$add.'" class="pg_page" onclick="return false;">'.$k.'</a><span class="sound_only">페이지</span>'.PHP_EOL;
else
$str .= '<span class="sound_only">열린</span><strong class="pg_current">'.$k.'</strong><span class="sound_only">페이지</span>'.PHP_EOL;
}
}
if ($total_page > $end_page) $str .= '<a href="'.$url.($end_page+1).$add.'" class="pg_page pg_next">다음</a>'.PHP_EOL;
if ($cur_page < $total_page) {
$str .= '<a href="'.$url.$total_page.$add.'" class="pg_page pg_end" onclick="return false;">맨끝</a>'.PHP_EOL;
}
if ($str)
return "<nav class=\"pg_wrap\"><span class=\"pg\">{$str}</span></nav>";
else
return "";
}
echo itemqa_page(10, $page, $total_page, "./itemqa.php?it_id=$it_id&amp;page=", "");
?>
<div id="sit_qa_wbtn">
<!-- <a href="javascript:itemqawin('it_id=<?php echo $it_id; ?>');">상품문의 쓰기<span class="sound_only"> 새 창</span></a> -->
<a href="<?php echo $itemqa_form; ?>" onclick="return false;" class="btn02 itemqa_form">상품문의 쓰기<span class="sound_only"> 새 창</span></a>
<a href="<?php echo $itemqa_list; ?>" id="itemqa_list" class="btn01">더보기</a>
</div>
<script>
$(function(){
$(".itemqa_form").click(function(){
window.open(this.href, "itemqa_form", "width=800,height=550");
});
$(".qa_href").click(function(){
var $content = $("#qa_div"+$(this).attr("target"));
$(".qa_div").each(function(index, value){
if ($(this).get(0) == $content.get(0)) { // 객체의 비교시 .get(0) 를 사용한다.
$(this).is(":hidden") ? $(this).show() : $(this).hide();
} else {
$(this).hide();
}
});
});
$(".pg_page").click(function(){
//alert($(this).attr("href"));
$(top.document).find('#itemqa').load($(this).attr("href"));
});
});
</script>
<?php
include_once(G4_PATH.'/tail.sub.php');
?>

82
shop/itemqaform.php Normal file
View File

@ -0,0 +1,82 @@
<?php
include_once("./_common.php");
include_once(G4_CKEDITOR_PATH.'/ckeditor.lib.php');
// 상품문의의 내용에 쓸수 있는 최대 글자수 (한글은 영문3자)
$iq_question_max_length = 10000;
$w = escape_trim($_REQUEST['w']);
$it_id = escape_trim($_REQUEST['it_id']);
$iq_id = escape_trim($_REQUEST['iq_id']);
if (!$is_member) {
alert_login("상품문의는 회원만 작성 가능합니다.", urlencode($_SERVER['REQUEST_URI']));
}
if ($w == "u")
{
$qa = sql_fetch(" select * from {$g4['shop_item_qa_table']} where iq_id = '$iq_id' ");
if (!$qa) {
alert_close("상품문의 정보가 없습니다.");
}
$it_id = $qa['it_id'];
if (!$iq_admin && $qa['mb_id'] != $member['mb_id']) {
alert_close("자신의 상품문의만 수정이 가능합니다.");
}
}
include_once(G4_PATH.'/head.sub.php');
?>
<style>
ul {list-style:none;margin:0px;padding:0px;}
label {width:130px;vertical-align:top;padding:3px 0;}
</style>
<div style="padding:10px;">
<form name="fitemqa" method="post" action="./itemqaformupdate.php" onsubmit="return fitemqa_submit(this);" autocomplete="off">
<input type="hidden" name="w" value="<?php echo $w; ?>">
<input type="hidden" name="it_id" value="<?php echo $it_id; ?>">
<input type="hidden" name="iq_id" value="<?php echo $iq_id; ?>">
<fieldset style="padding:0 10px 10px;">
<legend><strong>상품문의 쓰기</strong></legend>
<ul style="padding:10px;">
<li>
<label for="iq_subject">제목</label>
<input type="text" id="iq_subject" name="iq_subject" size="100" class="ed" minlength="2" maxlength="250" required itemname="제목" value="<?php echo get_text($qa['iq_subject']); ?>">
</li>
<li>
<label for="" style="width:200px;">질문</label>
<?php echo editor_html('iq_question', $qa['iq_question']); ?>
</li>
</ul>
<input type="submit" value=" 확 인 ">
</fieldset>
</form>
</div>
<script type="text/javascript">
self.focus();
function fitemqa_submit(f)
{
<?php echo get_editor_js('iq_question'); ?>
if (iq_question_editor_data.length > <?php echo $iq_question_max_length; ?>) {
alert("내용은 <?php echo $iq_question_max_length; ?> 글자 이내에서 작성해 주세요. (한글은 영문 3자)\n\n현재 : "+iq_question_editor_data.length+" 글자");
CKEDITOR.instances.iq_question.focus();
return false;
}
return true;
}
$(function() {
$("#iq_subject").focus();
});
</script>
<?php
include_once(G4_PATH.'/tail.sub.php');
?>

70
shop/itemqaformupdate.php Normal file
View File

@ -0,0 +1,70 @@
<?php
include_once('./_common.php');
if (!$is_member) {
alert_close("상품문의는 회원만 작성이 가능합니다.");
}
$iq_id = escape_trim($_REQUEST['iq_id']);
$iq_subject = escape_trim($_REQUEST['iq_subject']);
$iq_question = escape_trim($_REQUEST['iq_question']);
$iq_answer = escape_trim($_REQUEST['iq_answer']);
$hash = escape_trim($_REQUEST['hash']);
if ($w == "" || $w == "u") {
$iq_name = $member['mb_name'];
$iq_password = $member['mb_password'];
if (!$iq_subject) alert("제목을 입력하여 주십시오.");
if (!$iq_question) alert("질문을 입력하여 주십시오.");
}
$url = "./item.php?it_id=$it_id";
if ($w == "")
{
$sql = "insert {$g4['shop_item_qa_table']}
set it_id = '$it_id',
mb_id = '{$member['mb_id']}',
iq_name = '$iq_name',
iq_password = '$iq_password',
iq_subject = '$iq_subject',
iq_question = '$iq_question',
iq_time = '".G4_TIME_YMDHIS."',
iq_ip = '$REMOTE_ADDR' ";
sql_query($sql);
alert_opener("상품문의가 등록 되었습니다.", $url);
}
else if ($w == "u")
{
$sql = " select iq_password from {$g4['shop_item_qa_table']} where iq_id = '$iq_id' ";
$row = sql_fetch($sql);
if ($row['iq_password'] != $iq_password)
alert("패스워드가 틀리므로 수정하실 수 없습니다.");
$sql = " update {$g4['shop_item_qa_table']}
set iq_subject = '$iq_subject',
iq_question = '$iq_question'
where iq_id = '$iq_id' ";
sql_query($sql);
alert_opener("상품문의가 수정 되었습니다.", $url);
}
else if ($w == "d")
{
if (!$is_admin)
{
$sql = " select count(*) as cnt from {$g4['shop_item_qa_table']} where mb_id = '{$member['mb_id']}' and iq_id = '$iq_id' ";
$row = sql_fetch($sql);
if (!$row['cnt'])
alert("자신의 상품문의만 삭제하실 수 있습니다.");
}
//$sql = " delete from {$g4['shop_item_qa_table']} where mb_id = '{$member['mb_id']}' and iq_id = '$iq_id' ";
$sql = " delete from {$g4['shop_item_qa_table']} where iq_id = '$iq_id' and md5(concat(iq_id,iq_time,iq_ip)) = '{$hash}' ";
sql_query($sql);
alert("상품문의가 삭제 되었습니다.", $url);
}
?>

View File

@ -1,112 +0,0 @@
<?php
include_once('./_common.php');
include_once(G4_GCAPTCHA_PATH.'/gcaptcha.lib.php');
if ($w == '' || $w == 'u')
{
/*
if (!(trim($iq_key) && trim($iq_key) == get_session('ss_norobot_key'))) {
alert('자동등록방지 코드가 틀립니다.');
}
*/
if (!chk_captcha()) {
alert('자동등록방지 숫자가 틀렸습니다.');
}
/*
// 두개씩 비교할 필요가 없음
// 세션에 저장된 토큰과 폼으로 넘어온 토큰을 비교하여 틀리면 에러
if ($token && get_session("ss_token") == $token) {
// 맞으면 세션을 지워 다시 입력폼을 통해서 들어오도록 한다.
set_session("ss_token", "");
} else {
alert_close("토큰 에러");
}
*/
if (!$is_member)
{
if (!trim($_POST['iq_name'])) alert('이름을 입력하여 주십시오.');
if (!trim($_POST['iq_password'])) alert('패스워드를 입력하여 주십시오.');
}
else
{
$iq_name = $member['mb_name'];
$iq_password = $member['mb_password'];
}
$iq_password = sql_password($iq_password);
if (!trim($_POST['iq_subject'])) alert('제목을 입력하여 주십시오.');
if (!trim($_POST['iq_question'])) alert('내용을 입력하여 주십시오.');
}
$url = "./item.php?it_id=$it_id";
if ($w == '')
{
$sql = " select max(iq_id) as max_iq_id from {$g4['shop_item_qa_table']} ";
$row = sql_fetch($sql);
$max_iq_id = $row['max_iq_id'];
$sql = " select max(iq_id) as max_iq_id from {$g4['shop_item_qa_table']}
where it_id = '$it_id'
and mb_id = '{$member['mb_id']}' ";
$row = sql_fetch($sql);
if ($row['max_iq_id'] && $row['max_iq_id'] == $max_iq_id)
alert('같은 상품에 대하여 계속해서 질문 하실 수 없습니다.');
$sql = "insert {$g4['shop_item_qa_table']}
set it_id = '$it_id',
mb_id = '{$member['mb_id']}',
iq_name = '$iq_name',
iq_password = '$iq_password',
iq_subject = '$iq_subject',
iq_question = '$iq_question',
iq_time = '".G4_TIME_YMDHIS."',
iq_ip = '$REMOTE_ADDR' ";
sql_query($sql);
goto_url($url);
}
else if ($w == 'u')
{
$sql = " select iq_password from {$g4['shop_item_qa_table']} where iq_id = '$iq_id' ";
$row = sql_fetch($sql);
if ($row['iq_password'] != $iq_password)
alert('패스워드가 틀리므로 수정하실 수 없습니다.');
$sql = " update {$g4['shop_item_qa_table']}
set iq_subject = '$iq_subject',
iq_question = '$iq_question'
where iq_id = '$iq_id' ";
sql_query($sql);
goto_url($url);
}
else if ($w == 'd')
{
if ($is_member)
{
$sql = " select count(*) as cnt from {$g4['shop_item_qa_table']} where mb_id = '{$member['mb_id']}' and iq_id = '$iq_id' ";
$row = sql_fetch($sql);
if (!$row['cnt'])
alert('자신의 상품문의만 삭제하실 수 있습니다.');
}
else
{
$iq_password = sql_password($iq_password);
$sql = " select iq_password from {$g4['shop_item_qa_table']} where iq_id = '$iq_id' ";
$row = sql_fetch($sql);
if ($row['iq_password'] != $iq_password)
alert('패스워드가 틀리므로 삭제하실 수 없습니다.');
}
$sql = " delete from {$g4['shop_item_qa_table']} where mb_id = '{$member['mb_id']}' and iq_id = '$iq_id' ";
sql_query($sql);
goto_url($url);
}
?>

View File

@ -10,7 +10,7 @@ $it_id = escape_trim($_REQUEST['it_id']);
$is_id = escape_trim($_REQUEST['is_id']);
if (!$is_member) {
alert("사용후기는 회원만 평가가 가능합니다.", G4_BBS_URL."/login.php");
alert_close("사용후기는 회원만 작성 가능합니다.");
}
if ($w == "") {

View File

@ -2,7 +2,7 @@
include_once('./_common.php');
if (!$is_member) {
alert_close("사용후기는 회원만 등록이 가능합니다.");
alert_close("사용후기는 회원만 작성이 가능합니다.");
}
$is_subject = trim($_REQUEST['is_subject']);