include_once "../../mik_lib/common.lib.php";
// session_save_path(SESSION_PATH);
session_start();
include_once(__CASTLE_PHP_VERSION_BASE_DIR__."/castle_referee.php");
xss_replace();
$act = $_REQUEST['act'];
switch ($act)
{
case 'add_option' : //옵션 선택
debug($_GET);
$po_idx = (int)$_GET['po_idx'];
if (!$po_idx)
{
exit;
}
$qry = "SELECT * FROM pow_product_option WHERE po_idx = $po_idx AND po_num > 0";
$row = sql_fetch_row($qry);
if (!$row)
{
exit;
}
echo '
';
break;
case 'set_basket' : // 장바구니 넣기
$b_uid = $_SESSION['pow_uid'];
if (!$b_uid)
{
$b_sidx = $_SESSION['no_sid'];
}
$b_type = 1;
$op_idx[] = (int)$_GET['po_idx'];
$op_num = 1;
if (!$op_idx || !$op_num || !$b_type)
{
alert('상품정보가 없습니다. 다시한번 확인 해 주세요.');
exit;
}
$ok_num = 0;
foreach ($op_idx as $idx=>$val)
{
$b_poidx = $val;
$b_num = 1;
if ($b_poidx && $b_num)
{
//상품 불러오기
$row = sql_fetch_row("SELECT * FROM pow_product p INNER JOIN pow_product_option po ON p_idx = po_pidx WHERE po_idx = $b_poidx AND p_use = 'Y' AND p_status = 'O' AND po_num >= $b_num ");
if ($row)
{
$arr_in = array();
//기존거 불러와서 있으면 업데이트 없으면 등록
$row2 = sql_fetch_row("SELECT * FROM pow_basket WHERE b_uid = '$b_uid' AND b_sidx = '$b_sidx' AND b_poidx = $b_poidx AND b_type = 1 ");
if ($row2)
{
$arr_in['b_num'] = $row2['b_num'] + $b_num;
update_sql('pow_basket' , $arr_in , 'b_idx' , $row2['b_idx']);
}
else
{
$arr_in['b_num'] = $b_num;
$arr_in['b_uid'] = $b_uid;
$arr_in['b_poidx'] = $b_poidx;
$arr_in['b_sidx'] = $b_sidx;
$arr_in['b_type'] = $b_type;
insert_sql('pow_basket' , $arr_in);
}
$ok_num ++;
}
}
}
if ($ok_num)
{
$str_ok = '상품이 장바구니에 담겼습니다.';
}
else
{
$str_ok = '처리가 실패했습니다. 다시확인해 주세요.';
}
echo '
';
exit;
break;
case 'app_insert' : //상품평가 입력
$p_idx = (int)$_POST['p_idx'];
if (!$p_idx)
{
alert_close('데이터가 없습니다.');
}
if (!$_SESSION['pow_uid'])
{
alert_close('로그인 하셔야 상품후기 등록이 가능 합니다.');
}
$a_point = (int)$_POST['a_point'];
$a_comment = $_POST['a_comment'];
if (!$a_point || !$a_comment)
{
alert_back('데이터가 없습니다.');
}
$arr_in = array();
$arr_in['a_pidx'] = $p_idx;
$arr_in['a_point'] = $_POST['a_point'];
$arr_in['a_comment'] = $_POST['a_comment'];
$arr_in['a_wdate'] = date('Y-m-d H:i:s');
$arr_in['a_uid'] = $_SESSION['pow_uid'];
insert_sql('pow_app' , $arr_in);
//평균내서 업데이트
$prd_app = sql_fetch_row("SELECT COUNT(*) AS cnt , AVG(a_point) AS pp FROM pow_app WHERE a_pidx = $p_idx GROUP BY a_pidx");
sql_query("UPDATE pow_product SET p_app = '".((float)$prd_app['pp'])."' , p_app_cnt = '".((float)$prd_app['cnt'])."' WHERE p_idx = $p_idx ");
alert_opener('등록 하였습니다.');
break;
case 'pqna_insert' :
if(!$_SESSION['pow_uid']){
alert_close("로그인 후 이용 가능합니다.");
exit();
}
$p_idx = $_POST['p_idx'];
$b_bid = $_POST['table'];
$b_subject=$_POST['b_subject'];
$b_name=($_POST['b_name'])?$_POST['b_name']:$_SESSION['pow_name'];
$b_uid=$_SESSION['pow_uid'];
$b_email=($_POST['b_email'])?$_POST['b_email']:$_SESSION['pow_email'];
$b_content=$_POST['b_content'];
$b_short=$_POST['b_short'];
$b_is_notice=(int)$_POST['b_is_notice'];
$b_ip=$_SERVER['REMOTE_ADDR'];
$b_category=(int)$_POST['b_category'];
$b_homepage=$_POST['b_homepage'];
$b_pwd=($_POST['b_pwd'])?$_POST['b_pwd']:'pow';
$b_is_secret=(int)$_POST['b_is_secret'];
$b_reply=$_POST['b_reply'];
$b_etc1=$_POST['b_etc1'];
$b_etc2=$_POST['b_etc2'];
$b_etc3=$_POST['b_etc3'];
$b_etc4=$_POST['b_etc4'];
$b_etc6=$_POST['b_etc6'];
$b_etc7=$_POST['b_etc7'];
$b_etc8=$_POST['b_etc8'];
$b_etc9=$_POST['b_etc9'];
if ($table == 'place')
{
$addr = str_replace(' ' , '' , $b_etc2.$b_etc3.$b_etc4);
$url = "http://openapi.map.naver.com/api/geocode.php?key=".NAVER_MAP."&encoding=utf-8&coord=tm128&query=".$addr;
$arr = my_xml2array($url);
$b_etc7 = $arr[0][2][0][0]['x'];
$b_etc8 = $arr[0][2][0][1]['y'];
}
if(!$b_name || !$b_subject || !$b_content)
{
alert_back("필수데이터가 없습니다. 로그인중이시라면 다시로그인 후 이용해 주세요.");
}
$sql="insert into pow_board_content
(b_bid , b_name , b_pwd , b_uid , b_homepage , b_email , b_subject , b_content , b_short , b_category , b_is_secret , b_is_notice , b_wdate , b_ip , b_etc1 , b_etc2 , b_etc3 , b_etc4 , b_reply , b_etc6 , b_etc7 , b_etc8 , b_etc9)
values
('$b_bid' , '$b_name',password('$b_pwd'),'$b_uid','$b_homepage','$b_email','$b_subject','$b_content','$b_short',$b_category,'$b_is_secret','$b_is_notice',now(),'$b_ip','$p_idx','$b_etc2','$b_etc3','$b_etc4','$b_reply','$b_etc6','$b_etc7','$b_etc8','$b_etc9')";
$res=mysql_query($sql);
$iid=mysql_insert_id();
$sql="update pow_board_content set b_grp=$iid where b_idx=$iid";
$res=mysql_query($sql);
if($res)
{
//파일업로드
for($i=0;$i<$arr_config['bc_file'];$i++)
{
if($_FILES["fname".$i]["name"])
{
if($_FILES["fname".$i]["size"] > (5*1024*1024))
{
alert_back("5mb 이하만 가능합니다.");
}
//업로드한파일명
$file=$_FILES["fname".$i]["name"];
//확장자제한
$arr_ext = array("htm","html","js","php","asp","exe","com","dll","jsp","class","php3","aspx");
$temp_name = explode(".",$file);
$ext = strtolower($temp_name[sizeof($temp_name)-1]);
if (in_array($ext,$arr_ext))
{
alert_back("업로드가 불가능한 파일종류입니다.");
}
//실제로 업로드될 파일명
$file_up=$iid.'_'.$i.'_'.time().'.'.$ext;
$target=DROOT.BOARD_FROOT."/".$table."/".$file_up;
move_uploaded_file($_FILES["fname".$i]["tmp_name"],$target);
//이미지일경우 일단 섬네일 파일 생성
if(ox_imgfile($file))
{
thumnail($target, $file_up,DROOT.BOARD_FROOT."/".$table."/thumb/", $thum_w , $thum_h);
}
$sql="insert into pow_board_file values('','$table',$iid,'$file','$file_up',0)";
$res=mysql_query($sql);
}
}
}
if($res)
{
if ($table == 'pqna' && !is_admin())
{
alert("등록하였습니다.");
echo "";
}
alert("글을 등록 하였습니다.");
echo "";
}
else
{
alert_back("글등록이 실패했습니다. 다시 시도해주세요");
}
$ist_qry = "";
break;
case 'insert_compare' : // 비교
$c_uid = $_SESSION['pow_uid'];
if (!$c_uid)
{
$c_sid = $_SESSION['no_sid'];
$where = " AND c_sid = '$c_sid' ";
}
else
{
$where = " AND c_uid = '$c_uid' ";
}
$c_pidx = (int)$_GET['p_idx'];
if (!$c_pidx)
{
alert('상품정보가 없습니다. 다시한번 확인 해 주세요.');
exit;
}
//기존거 있나 확인
$row = sql_fetch_row("SELECT * FROM pow_compare WHERE c_pidx = '$c_pidx' $where ");
if (!$row)
{
$arr_in = array();
$arr_in['c_uid'] = $c_uid;
$arr_in['c_sid'] = $c_sid;
$arr_in['c_pidx'] = $c_pidx;
$arr_in['c_wdate'] = date('Y-m-d H:i:s');
insert_sql('pow_compare' , $arr_in);
}
sleep(1);
if ($_SESSION['pow_uid'])
{
$cwhere = " AND c_uid = '".$_SESSION['pow_uid']."' ";
}
else
{
$cwhere = " AND c_sid = '".$_SESSION['no_sid']."' ";
}
$arr_compare = sql_fetch_array("SELECT p.* , c.* , GROUP_CONCAT(pc_cate) AS ca_code FROM pow_compare c INNER JOIN pow_product p ON p_idx = c_pidx INNER JOIN pow_product_cate pc ON p_idx = pc_pidx WHERE p_use = 'Y' AND p_status IN ('O' , 'N') AND (p_show_chk = '1' OR (p_show_sdate <= '$now' AND p_show_edate >= '$now' )) $cwhere GROUP BY p_idx ORDER BY c_idx DESC");
echo '
';
alert('등록하였습니다.');
exit;
break;
case 'delete_compare' ://비교삭제
$c_idx = (int)$_GET['c_idx'];
if (!$c_idx)
{
alert_back('데이터가 없습니다.');
}
if ($_SESSION['pow_uid'])
{
$cwhere = " AND c_uid = '".$_SESSION['pow_uid']."' ";
}
else
{
$cwhere = " AND c_sid = '".$_SESSION['no_sid']."' ";
}
sql_query("DELETE FROM pow_compare WHERE c_idx = '$c_idx' $cwhere");
goto_url('/inc/pop_compare.php');
break;
}
?>