<!--#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 = "ebp_idx, ebp_subject, ebp_code, ebp_wdate, ebp_mdate, ebp_chk, eb_pk"

Call RequestAll (R_Fields, "UploadForm")


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


If ebp_idx = "" then ' 저장
	

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

	' 썸네일1
	Call GD2_make_thumb(413, 584, ebp_pageimg, strDir, strDir&"middle\" )

	' 썸네일2
	Call GD2_make_thumb(50, 71, ebp_pageimg, strDir, strDir&"small\" )



	' 순서
	' *****************************************
	sql = " SELECT isnull(max(ebp_code),0) FROM ebook_page  WHERE eb_pk = "&eb_pk
	Set Rs = Dbcon.Execute (sql)
	ebp_code = rs(0)
	rs.close : Set rs = Nothing
	
	ebp_code = ebp_code + 1
	' *****************************************

	
	R_Fields_i = "ebp_subject, ebp_code, ebp_pageimg, ebp_wdate, ebp_mdate, ebp_chk, eb_pk"
	
	ebp_wdate = getDateFm(now,3)
	ebp_mdate = getDateFm(now,3)
	ebp_chk	= "Y"
	
	Call InsertQuery (R_Fields_i, "ebook_page")
	
	ok_url = "write_ui.asp?eb_pk="&eb_pk


Else ' 수정
	
	ebp_subject = UploadForm("ebp_subject_"&ebp_idx) ' 수정이름
	ebp_pageimg = UploadForm("ebp_pageimg_"&ebp_idx) ' 수정파일
	ebp_pageimg_name = UploadForm("ebp_pageimg_"&ebp_idx&"_name") ' 수정파일

	ebp_pageimg_org = UploadForm("ebp_pageimg_org_"&ebp_idx) ' 수정파일
	ebp_pageimg_del = UploadForm("ebp_pageimg_del_"&ebp_idx) ' 수정파일

		
	strDir	= rootPath & "\data\ebook\"&eb_pk&"\"
	strDir2	= rootPath & "\data\ebook\"&eb_pk&"\middle\"
	strDir3	= rootPath & "\data\ebook\"&eb_pk&"\small\"



	If ebp_pageimg<>"" Then

		ext_str		= "jpg,gif"
		ebp_pageimg	= wfile2("ebp_pageimg_"&ebp_idx, 10, strDir, ext_str)

		' 썸네일1
		Call GD2_make_thumb(413, 584, ebp_pageimg, strDir, strDir&"middle\" )

		' 썸네일2
		Call GD2_make_thumb(50, 71, ebp_pageimg, strDir, strDir&"small\" )

		Call dfile(strDir, ebp_pageimg_org)
		Call dfile(strDir2, ebp_pageimg_org)
		Call dfile(strDir3, ebp_pageimg_org)


	Else

		ebp_pageimg = ebp_pageimg_org
		If ebp_pageimg_del <> "" then ' 첨부파일만 삭제
			Call dfile(strDir, ebp_pageimg_org)
			Call dfile(strDir2, ebp_pageimg_org)
			Call dfile(strDir3, ebp_pageimg_org)
			ebp_pageimg = ""
		End if

	End If
	
	
	
	R_Fields = "ebp_subject, ebp_mdate, ebp_pageimg"

	ebp_mdate = getDateFm(now,3)

	Call UpdateQuery (R_Fields, "ebook_page", "where ebp_idx="&ebp_idx)

	ok_url = "write_ui.asp?eb_pk="&eb_pk

End If

Dbcon.close : Set Dbcon = nothing

Call loding("0", ok_url)

%>