<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import ="bbs.BbsDAO" %>
<%@page import="user.UserDAO"%>
<%@ page import="java.io.File" %>
<%@ page import ="java.io.PrintWriter" %>
<%@ page import="java.io.IOException" %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy" %>
<% request.setCharacterEncoding("UTF-8"); %>
<jsp:useBean id="bbs" class="bbs.Bbs" scope="page"/>
<jsp:setProperty name="bbs" property="*"/>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TKmall</title>
</head>
<body>
			

	<%
		String ID = null;
		if (session.getAttribute("ID") != null) {
			ID = (String) session.getAttribute("ID");
		}
		
		int USER_TYPE = 1;
		UserDAO u = new UserDAO();
		USER_TYPE = u.fmanager(ID);
		int pnum = Integer.parseInt(request.getParameter("pnum"));
		if(USER_TYPE != 0){
			PrintWriter script = response.getWriter();
			script.println("<script>");
			script.println("alert('권한 없음.')");
			script.println("location.href = 'login.jsp'");
			script.println("</script>");
		}else{
			String proname = request.getParameter("proname");
	        String kind = request.getParameter("kind");
	        String brand = request.getParameter("brand");
	        int price = Integer.parseInt(request.getParameter("price"));
	        int rprice = Integer.parseInt(request.getParameter("rprice"));
	        String stype = new String();
	        stype = request.getParameter("type");
	        String ex = request.getParameter("ex");
	        
	        
			if(kind == null || brand == null || proname == null || request.getParameter("price") == null || request.getParameter("rprice") == null){
					PrintWriter script = response.getWriter();
					script.println("<script>");
					script.println("alert( '입력이 안된 사항이 있습니다.')");
					script.println("history.back()");
					script.println("</script>");
				} else{
					BbsDAO b = new BbsDAO();
					int result = b.update(kind, brand, proname, price, rprice, ex, stype, pnum); // 실제로 게시글 작성
					if(result == -1){	//이미 존재하는 아이디
						PrintWriter script = response.getWriter();
						script.println("<script>");
						script.println("alert('글쓰기에 실패했습니다.')");
						script.println("history.back()");
						script.println("</script>");
					}else {
						PrintWriter script = response.getWriter();
						script.println("<script>");
						script.println("location.href = 'main.jsp'");
						script.println("</script>");
					}
				}
		}
	%>
</body>
</html>