<!--#include virtual = "/common/lib/dbcon.asp" -->
<!--#include virtual = "/common/lib/func.asp" -->

<!--#include file = "config.asp" -->

<%

rootPath = server.MapPath("/")

Set UploadForm = Server.CreateObject("DEXT.FileUpload")
UploadForm.DefaultPath = rootPath & "\data\"

R_Fields = "eb_idx, eb_subject, eb_skin, eb_pages, eb_logoimg_org, eb_logoimg_del, eb_chk, eb_viewtype"

Call RequestAll (R_Fields, "UploadForm")

' $nsc_copyright = InputValue2($nsc_copyright);


' ------------------- 저장공간인 [DATA]폴더가 없다면 생성 한다. -------------------
FolderCreate( rootPath & "\data\ebook\")
FolderCreate( rootPath & "\data\ebook\logo\")
' ------------------------------------------------------------------------------------

If eb_idx = "" then ' 저장

	eb_pk		= get_idx_add()
	FolderCreate( rootPath & "\data\ebook\" & eb_pk & "\")
	

	' 순서
	' *****************************************
	sql = " SELECT isnull(max(eb_code),0) FROM ebook"
	Set Rs = Dbcon.Execute (sql)
	eb_code = rs(0)
	rs.close : Set rs = Nothing
	
	eb_code = eb_code + 1
	' *****************************************


	' 이미지파일저장 --------------------------------------
	strDir		= rootPath & "\data\ebook\logo\"
	ext_str		= "jpg,gif"
	eb_logoimg	= wfile2("eb_logoimg", 10, strDir, ext_str)
	' ------------------------------------------------------



	' 기본페이지 설정 --------------------------------------
	If eb_pages <> "" then

		R_Fields_i = "ebp_subject, ebp_code, ebp_pageimg, ebp_wdate, ebp_mdate, ebp_chk, eb_pk"

		For z=1 To eb_pages

			ebp_subject	= "page"&z
			ebp_code	= z
			ebp_pageimg	= ""
			ebp_chk		= "Y"

			ebp_wdate = getDateFm(now,3)
			ebp_mdate = getDateFm(now,3)

			Call InsertQuery(R_Fields_i, "ebook_page")

		
		next
	End if
	' ------------------------------------------------------



	R_Fields_i = "eb_subject, eb_code, eb_skin, eb_logoimg, eb_wdate, eb_mdate, eb_chk, eb_pk, eb_viewtype"
	eb_wdate	= getDateFm(now,3)
	eb_mdate	= getDateFm(now,3)
	Call InsertQuery(R_Fields_i, "ebook")

	ok_url = "list.asp?"&page_info



else ' 수정



	strDir		= rootPath & "\data\ebook\logo\"
	ext_str		= "jpg,gif"
	eb_logoimg	= wfile2("eb_logoimg", 10, strDir, ext_str)


	If eb_logoimg <> "" then ' 첨부파일이 있으면
	
		Call dfile(strDir, eb_logoimg_org)

	Else
	
		eb_logoimg = eb_logoimg_org

		If eb_logoimg_del <> "" then ' 첨부파일만 삭제
			Call dfile(strDir, eb_logoimg_org)
			eb_logoimg = ""
		End if
		
	End if	


	R_Fields_u = "eb_subject, eb_skin, eb_logoimg, eb_wdate, eb_mdate, eb_chk, eb_viewtype"
	eb_mdate	= getDateFm(now,3)
	Call UpdateQuery (R_Fields_u, "ebook", "where eb_idx="&eb_idx)


	ok_url = "list.asp?"&page_info

End if


Dbcon.close : Set Dbcon = Nothing

Call loding("0",ok_url)

%>