<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page session="true" %>
<% request.setCharacterEncoding("utf-8");%>
<html>
<head>
	<title>권한부여</title>
</head>
<body>
<%
String authority = (String)session.getAttribute("authority"); //세션에서 권한값 가져오기
String id = request.getParameter("id");
ResultSet rs=null;
String check="";
String sql=null;
try{
	
	   Class.forName("oracle.jdbc.driver.OracleDriver");
	   Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@168.126.146.45:1521:orcl","20161505","961120");
	   sql="select * from log_member where id=? ";
	   PreparedStatement pstmt=conn.prepareStatement(sql);
	   pstmt.setString(1, id);
	   
	   rs=pstmt.executeQuery(); //결과 가져옴
	  
	  if(rs.next()){//if인지 while인지 확인. //6월2일 여기까지(giveAuthority.jsp먼저 수정한뒤 takeAuthority.jsp맞춰서 수정하기)
	  	  pstmt=conn.prepareStatement("update log_member set authority=0 where id=? ");
		                                    //UPDATE 테이블명 SET 컬럼명=새로운값 WHERE 업데이트조건 
		  pstmt.setString(1,id);
		  
		  pstmt.executeUpdate(); 

			check="1";
	}
}catch(Exception e){
e.printStackTrace();
}finally{
}

if(check.equals("1")){ %>
			<script>
				alert("해당 아이디의 권한을 일반사용자로 변경되었습니다.");
				location.href="../../list.jsp";
			</script>


<%} else {%>
	<script>
		alert("일치하는 아이디가 없습니다.");
		location.href="giveAuthorityForm.jsp";
	</script>


<%
	
}
%>
</body>
</html>