<!--#include virtual="/common/lib/func.asp"-->
<%
'Dim R_Fields, UploadForm
'Dim b_num, b_type, b_id, b_name, b_pwd, b_subject, b_email, b_jumin, b_phone1, b_phone2, b_phone3, b_noticechk, b_ip, b_count, b_look, b_open, b_ref, b_step, b_level, b_regdate, b_chuchun, b_sbjclr, b_temp1, b_temp2, b_temp3, b_temp4,b_temp5, b_temp6, b_temp7, b_file1, b_file2, b_file3, b_file4, b_file5,b_keyword,w_mode, b_cate_tot
'Dim b_sdate_y, b_sdate_m, b_sdate_d, b_edate_y, b_edate_m, b_edate_d, b_zip1, b_zip2, b_addr1, b_addr2


b_sdate = b_sdate_y & "-" & Right( "0" & b_sdate_m, 2) & "-" & Right("0" & b_sdate_d, 2)
b_edate = b_edate_y & "-" & Right( "0" & b_edate_m, 2) & "-" & Right("0" & b_edate_d, 2)



'//*******************  금지단어 체크기능  ***********************
If trim(a_noword) <> "" then
	a_noword = Split(a_noword, ",")		'//제한파일..

	for z=0 To UBound( a_noword )

		iscontent = instr(b_content, a_noword(z))		'//내용에서 검색
		issubject = instr(b_subject, a_noword(z))		'//글제목에서 검색..

		if iscontent > 0 Or issubject > 0 then
			Call Back_back ( a_noword(z) & "은(는) 사용금지단어입니다. \n단어를 삭제하세요." )
		End if

	next
End if
'//*****************************************************************

If w_mode = "W" Or w_mode = "WR" then		'//저장

	
	If a_upload = "Y" then		'//첨부파일 사용일때
		
		'//폴더 없으면 새로 생성
		strDirectory		= server.mappath("/data/board/") & "\" & a_tablename& "\"
		Call FolderCreate( strDirectory )
		

		'//폴더 없으면 새로 썸네일용
		strDirectory2		= strDirectory & "thum\"
		Call FolderCreate( strDirectory2 )

		'//첨부파일체크
		for z = 1 To a_upload_len

			strDir		= strDirectory
			ext_str		= a_nofile

			'파일저장
			b_file		= wfile2("b_file" & z, a_nofilesize, strDir, ext_str)		'필드명, 최대용량, 업로드경로, 허용파일(zip,gif,jpg...)
			

			If b_file <> "" Then
				execute ("b_file" & z & "=" & b_file)

				ext_chk_arr = Split( b_file, "." )
				ext_chk = LCase( ext_arr( UBound(ext_arr) ) )

				If ext_chk = "jpg" Or ext_chk = "gif" then
					'//썸네일
					Call GD2_make_thumb( 130, 100, b_file, strDirectory2 )
				End if
			End if
		next

	End if

	


	'//ref,step,level 체크
	If b_type = "R" then	'//답변이면

		sql = "UPDATE " & a_tablename & " SET b_step = b_step+1  WHERE b_ref = " & b_ref & "  AND b_step > " & b_step
		dbcon.execute sql

		b_step		= b_step + 1
		b_level		= b_level + 1

	End if
	


	

	b_cate		= ""
	b_count		= 0
	b_look		= "Y"	'//사용/중지
	'//$b_open		= "Y"; //공개/비공개
	b_id		= SESSION("ss_m_id")
	b_regdate	= getDateFm(Now(), 3)
	b_ip		= request.ServerVariables("REMOTE_ADDR")
	b_chuchun	= 0

	If a_cate = "Y" then
		
		If b_type = "R" then	'//답변이면 //상위분류값을 넣는다..

			SQL = "SELECT b_cate, b_catename FROM " & a_tablename & " WHERE  b_num=" & b_ref
			Set rs_cate = dbcon.execute( sql )
			
			b_cate = rs_cate("b_cate")
			b_catename = rs_cate("b_catename")

			Set rs_cate = nothing

		else

			b_cate_str	= Split(b_cate_tot, ",")
			b_cate		= Trim(b_cate_str(0))
			b_catename	= Trim(b_cate_str(1))

		End if

	else

		b_cate = 0
		b_catename = ""

	End if
	
	b_c_count	= 0



	
	R_Fields_i = "b_type, b_id, b_name, b_pwd, b_subject, b_email, b_jumin, b_phone1, b_phone2, b_phone3, b_cate, b_catename, b_noticechk, b_content, b_ip, b_count, b_look, b_open, b_ref, b_step, b_level, b_regdate, b_chuchun, b_sbjclr, b_temp1, b_temp2, b_temp3, b_temp4, b_temp5, b_temp6, b_temp7, b_file1, b_file2, b_file3, b_file4, b_file5,b_keyword, b_c_count, b_zip1, b_zip2, b_addr1, b_addr2"
	'response.write "a_level="&a_level
	'response.end


	If a_level = "default_calendar" or a_level = "nninc_show" or a_level = "nninc_movie"  Then '//달력형태일때.. (전시회, 영화일정 추가 10.07.29)
		R_Fields_i = R_Fields_i & ", b_sdate, b_edate"
	End if

	
	Call InsertQuery ( R_Fields_i, a_tablename)

	

	If b_type = "N" then

		sql = "SELECT Max(b_num) as max_b_num FROM " & a_tablename
		Set rs1 = dbcon.execute( sql )

		max_b_num = rs1("max_b_num")

		sql = "UPDATE " & a_tablename & " SET b_ref = " & max_b_num & " WHERE b_num = " & max_b_num
		dbcon.execute sql

	End if

	ok_url = "list.asp?a_num=" & a_num & "&amp;" & page_info

elseIf w_mode = "M" then	'//수정



	If a_upload = "Y" then	'//첨부파일 사용일때

		
		'//폴더 없으면 새로 생성
		strDirectory		= server.mappath("/data/board/") & "\" & a_tablename & "\"
		Call FolderCreate( strDirectory )
		

		'//폴더 없으면 새로 썸네일용
		strDirectory2		= strDirectory & "thum\"
		Call FolderCreate( strDirectory2 )


		'//------------------------------------------------------------------------------
		For z=1 To a_upload_len
			b_file_chk	= UploadForm("b_file_chk" & z)
			b_file_org	= UploadForm("b_file_org" & z)
			ext_str		= a_nofile

			If b_file_chk <> "" Then		'//체크하면 파일삭제, 디비삭제
				
				strDir		= strDirectory
				strDir2		= strDirectory2

				Call dfile( strDir, b_file_chk)
				Call dfile( strDir2, b_file_chk)

				sql = "UPDATE " & a_tablename & " SET b_file" & z & " = '' WHERE b_num=" & b_num
				dbcon.execute sql

			End if

			'파일저장
			b_file		= wfile2("b_file" & z, b_file_size, strDirectory, ext_str)		'필드명, 최대용량, 업로드경로, 허용파일(zip,gif,jpg...)

			If b_file <> "" then		'//첨부파일 있으면

				strDir		= strDirectory
				strDir2		= strDirectory2


				If b_file_org <> "" then

					Call dfile( strDir, b_file_org )
					Call dfile( strDir2, b_file_org )

				End if


				ext_chk_arr = Split( b_file, "." )
				ext_chk = LCase( ext_arr( UBound(ext_arr) ) )

				If ext_chk = "jpg" Or ext_chk = "gif" then
				'//이미지파일저장
				'//*****************************************
				'//썸네일
				Call GD2_make_thumb( 130, 100, b_file, strDirectory2 )

				End If
				
				sql = "UPDATE " & a_tablename & " SET b_file" & z & " = '" & b_file & "' WHERE b_num=" & b_num
				dbcon.execute sql
				'//*****************************************

			End if

		next

	End if
	'//------------------------------------------------------------------------------

	if a_cate = "Y" then

		If b_type = "R" then	'//답변이면

			SQL = "SELECT b_cate, b_catename FROM " & a_tablename & " WHERE b_num=" & b_ref
			Set rs_cate = dbcon.execute( sql )

			b_cate = rs_cate("b_cate")
			b_catename = rs_cate("b_catename")

		else

			b_cate_str	= Split(b_cate_tot, ",")
			b_cate		= Trim(b_cate_str(0))
			b_catename	= Trim(b_cate_str(1))
		End if

		R_Fields2 = ",b_cate, b_catename"

	End if




	R_Fields = "b_name, b_pwd, b_subject, b_email, b_phone1, b_phone2, b_phone3,  b_noticechk, b_content, b_sbjclr, b_temp1, b_temp2, b_temp3, b_temp4, b_temp5, b_temp6, b_temp7, b_keyword, b_open" & R_Fields2

	If a_level = "default_calendar" or a_level = "nninc_show" or a_level = "nninc_movie"  then		'//달력형태일때.. (전시회, 영화일정 추가 10.07.29)
		R_Fields = R_Fields & ", b_sdate, b_edate"
	End if

	If a_home = "Y" then	'//주소사용시
		R_Fields = R_Fields & ", b_zip1, b_zip2, b_addr1, b_addr2"
	End if

	Call UpdateQuery ( R_Fields, a_tablename, " where b_num=" & b_num )

	ok_url = "list.asp?a_num=" & a_num & "&amp;" & page_info

End if

Call loding ("0", ok_url)

%>