<!-- #include virtual = "/common/lib/dbcon.asp" -->
<!-- #include virtual = "/common/lib/func.asp" -->
<%
Dim R_Fields, rs
Dim ct_idx, ct_code, ct_name, ct_ref, ct_depth, ct_chk, ct_wdate, ct_codeno, ct_url, ct_codeno_ref

R_Fields = "ct_idx, ct_code, ct_name, ct_ref, ct_depth, ct_chk, ct_wdate, ct_codeno, ct_url, ct_codeno_ref"

Call RequestAll (R_Fields, "request.form")

If ct_idx = "" then		'//저장


	'//순서
	'//*****************************************
	sql = "select max(ct_code) as ct_code from member_div WHERE ct_ref = " & ct_ref
	'response.write sql
	'response.end
	Set rs = dbcon.execute( sql )

	ct_code = rs("ct_code")

	if IsNull( ct_code ) or ct_code = "" then
		ct_code = 1
	else
		ct_code = ct_code + 1
	End if
	'//*****************************************



	
	R_Fields_i = "ct_code, ct_name, ct_ref, ct_depth, ct_chk, ct_wdate, ct_url"
	
	ct_wdate = getDateFm(Now(), 3)
	
	Call InsertQuery (R_Fields_i, "member_div")
	
	'//메뉴값 적용-----------------------------------------------------------------------------
	sql = "select max(ct_idx) as ct_idx  from member_div"
	Set rs1 = dbcon.execute( sql )

	max_ct_idx = rs1("ct_idx")

	
	ct_codeno	= ct_codeno_ref  & "C" & max_ct_idx & ";"

	sql = "update member_div set ct_codeno='" & ct_codeno & "' WHERE ct_idx = " & max_ct_idx
	dbcon.execute sql
	//-----------------------------------------------------------------------------------------

	If ct_ref = "0" then ct_ref = ""
	ok_url = "write.asp?ct_idx=" & ct_ref


Else		'//수정

	
	R_Fields = "ct_name, ct_wdate, ct_url"

	ct_wdate = getDateFm(Now(), 3)

	Call UpdateQuery (R_Fields, "member_div", "where ct_idx=" & ct_idx)

	If ct_ref = "0" then ct_ref = ""

	ok_url = "write.asp?ct_idx=" & ct_ref


End if

dbcon.close
Set dbcon = nothing

Call loding("0",ok_url)


%>