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

?>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<?
$chk = "0";

if($wr_subject == "" && $wr_1 == "" ){  ?> <script> alert("Please select product or barcode");   document.location.href="<?=$g4[path]?>/bbs/board.php?bo_table=<?=$bo_table?>" </script>  <?  $chk = "1"; }

if($wr_subject != "") $option = "wr_subject = '".$wr_subject."'";
else $option = "wr_1 = '".$wr_1."' ";

$query5 = "select * from g4_write_bsetup  where $option ";
$result5 = sql_query($query5);
while($row  = sql_fetch_array($result5)) {
	
	$place = $row[wr_3]; //구입처
	$maker = $row[wr_4]; //제조사
	$owner = $row[wr_5]; //담당자
		$product = $row[wr_subject]; //물품명
}

if($chk != "1") {
?>

<?
// 상품명과 바코드가 모두 빈 공간이면 에러로 돌아가라...

//sql_query(" update g4_write_setup set wr_3 = '$wr_3'  where $option ");

if($wr_5 == "") $wr_5 = $place;
if($wr_4 == "") $wr_4 = $owner;
$wr_8 = $wr_3/$wr_2;

$table = "g4_write_".$bo_table;
 $wr_num = get_next_num($table);

   $sql = " insert into $table
                set wr_num = '$wr_num',
                    wr_reply = '$wr_reply',
                    wr_comment = 0,
                    ca_name = '$ca_name',
                    wr_option = '$html,$secret,$mail',
                    wr_subject = '$wr_subject',
                    wr_content = '코멘트를 입력하세요.',
                    wr_link1 = '$wr_link1',
                    wr_link2 = '$wr_link2',
                    wr_link1_hit = 0,
                    wr_link2_hit = 0,
                    wr_trackback = '$wr_trackback',
                    wr_hit = 0,
                    wr_good = '$wr_good',
                    wr_nogood = 0,
                    mb_id = '$mb_id',
                    wr_password = '$wr_password',
                    wr_name = ' $wr_name',
                    wr_email = '$wr_email',
                    wr_homepage = '$wr_homepage',
                    wr_datetime = '$g4[time_ymdhis]',
                    wr_last = '$g4[time_ymdhis]',
                    wr_ip = '$_SERVER[REMOTE_ADDR]',
                    wr_1 = '$wr_1',
                    wr_2 = '$wr_2',
                    wr_3 = '$wr_3',
                    wr_4 = '$wr_4',
                    wr_5 = '$wr_5',
                    wr_6 = '$wr_6',
                    wr_7 = '$wr_7',
                    wr_8 = '$wr_8',
                    wr_9 = '$wr_9',
                    wr_10 = 'wr_10' ";

    sql_query($sql);

    $wr_id = mysql_insert_id();

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

    // 새글 INSERT
    //sql_query(" insert into $g4[board_new_table] ( bo_table, wr_id, wr_parent, bn_datetime ) values ( '$bo_table', '$wr_id', '$wr_id', '$g4[time_ymdhis]' ) ");
    sql_query(" insert into $g4[board_new_table] ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '$bo_table',  '$wr_id', '$wr_id', '$g4[time_ymdhis]', '$member[mb_id]' ) ");

    // 게시글 1 증가
    sql_query("update $g4[board_table] set bo_count_write = bo_count_write + 1 where bo_table = '$bo_table'");

}
?>

 <meta http-equiv="refresh" content="0; url=<?=$g4[path]?>/bbs/board.php?bo_table=<?=$bo_table?>">