<?

include_once("./_common.php");
include_once("$g4[path]/head.sub.php");

//cart config
include_once("$g4[path]/skin/cart/basic/config/cart_config.php");
//$cart_table[cart_category] = "g4_cart_category";

$write_table   =  $cart_table[cart_category];

if(!$wr_subject){
  alert("분류이름은 필수입니다.");
}


$se_01    = $_POST["se_01"];  
$wr_id    = $_POST["se_02"];  
$w        = $_POST["se_03"];

if ($w == "p") {
    $wr = get_write($write_table, $wr_id);
    if (!$wr[wr_id])
        alert("글이 존재하지 않습니다.\\n\\n글이 삭제되었거나 이동하였을 수 있습니다."); 
}


if ($w == "p"){


    // 게시글 배열 참조
    $reply_array = &$wr;


    $reply_len = strlen($reply_array[wr_reply]) + 1;

        $begin_reply_char = "A";
        $end_reply_char = "Z";
        $reply_number = +1;
        $sql = " select MAX(SUBSTRING(wr_reply, $reply_len, 1)) as reply from $write_table where wr_num = '$reply_array[wr_num]' and SUBSTRING(wr_reply, $reply_len, 1) <> '' ";

/**
        $begin_reply_char = "Z";
        $end_reply_char = "A";
        $reply_number = -1;
        $sql = " select MIN(SUBSTRING(wr_reply, $reply_len, 1)) as reply from $write_table where wr_num = '$reply_array[wr_num]' and SUBSTRING(wr_reply, $reply_len, 1) <> '' ";
**/

    if ($reply_array[wr_reply]) $sql .= " and wr_reply like '$reply_array[wr_reply]%' ";
    $row = sql_fetch($sql);

    if (!$row[reply])
        $reply_char = $begin_reply_char;
    else if ($row[reply] == $end_reply_char) // A~Z은 26 입니다.
        alert("더 이상 답변하실 수 없습니다.\\n\\n분류는 26개 까지만 가능합니다.");
    else
        $reply_char = chr(ord($row[reply]) + $reply_number);

    $reply = $reply_array[wr_reply] . $reply_char;
}



if ($w == "" || $w == "p") {

    if ($w == "p") 
    {

        $write = sql_fetch(" select wr_num from {$cart_table[cart_category]} where ne_1 = '$se_01' ");


        $wr_id = $wr_id . $reply;
        $wr_num = $write[wr_num];
        $wr_reply = $reply;
    } 
    else 
    {
        $wr_num = get_next_num($cart_table[cart_category]);
        $wr_reply = "";
    }


                // 주문정보에 업데이트한다.
  $sql = " insert into $cart_table[cart_category]
                set wr_num           = '$wr_num',
				    wr_reply         = '$wr_reply',
					wr_is_comment    = '$wr_is_comment',
					wr_comment       = '$wr_comment',
					wr_comment_reply = '$wr_comment_reply',
                    wr_subject       = '$wr_subject',
					wr_content       = '$wr_content',
					wr_datetime      = '$g4[time_ymdhis]e',
					mb_id            = '$member[mb_id]',
                    ne_1             = '$ne_1',
                    ne_2             = '$ne_2',
                    ne_3             = '$ne_3',
                    ne_4             = '$ne_4',
                    ne_5             = '$ne_5',
                    ne_6             = '$ne_6',
                    ne_7             = '$ne_7',
                    ne_8             = '$ne_8',
                    ne_9             = '$ne_9',
                    ne_10            = '$ne_10' ";

      $result    =      sql_query($sql);


    $wr_id = mysql_insert_id();

    // 부모 아이디에 UPDATE
    sql_query(" update $cart_table[cart_category] set wr_parent = '$wr_id' where wr_id = '$wr_id' ");

}
elseif($w == 'w'){

                // 주문정보에 업데이트한다.
    $sql = " update $cart_table[cart_category]
               set  wr_subject       = '$wr_subject',
					wr_content       = '$wr_content',
					wr_datetime      = '$g4[time_ymdhis]e',
					mb_id            = '$member[mb_id]',
                    ne_2             = '$ne_2',
                    ne_3             = '$ne_3',
                    ne_4             = '$ne_4',
                    ne_5             = '$ne_5',
                    ne_6             = '$ne_6',
                    ne_7             = '$ne_7',
                    ne_8             = '$ne_8',
                    ne_9             = '$ne_9',
                    ne_10            = '$ne_10' 
                     where ne_1    = '$ne_1' ";


      $result    =      sql_query($sql);

}







//분류카테고리로 이동
if($result){
$auto_url  =  "$g4[path]/cate/cart.php?order=category";
}
else{
echo '실패';
}

?>


<body onload="name_auto('1','<?=$med_path?>','','','','','<?=$auto_url?>')" > 

</body> 

<script language="JavaScript"> 
function name_auto(num, se_02, se_03, se_04, se_05, se_06, se_07) { 

   //if(num =='1') 
   //opener.fwrite.value     = se_02; 
   // window.close();
   //return false;

    if(num =='1')
     opener.Rink(se_07); 
      window.close();
     return false;
}  
</script> 



