<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.sql.*,gbase.db.*" %>
<%@ include file="../checkLogin.jsp" %>
<%
      String user_id=request.getParameter("user_id")==null?"":request.getParameter("user_id");
      String user_name=request.getParameter("user_name")==null?"":request.getParameter("user_name");
      DBOperation theDBOperation = new DBOperation();
      String sql ="";
      String login_user_id =session.getAttribute("user_id")==null?"":(String)session.getAttribute("user_id");
      sql="select * from web_role where web_account='"+web_account+"'";
      String sql1 = "select * from web_role a,web_user_role b where  a.web_account='"+web_account+"' and a.role_id=b.role_id and b.user_id='"+user_id+"'";
      
      
       ResultSet rs =theDBOperation.getResultSet(sql);
       ResultSet rs1 =theDBOperation.getResultSet(sql1);
       //request.setAttribute("ALL_ROLE", rs);
       //request.setAttribute("HAVE_ROLE", rs1);

%>
<html>
<head>
<title></title>
</head>
<script language="JavaScript">
	function save(obj ) {
	var len = obj.length;
	var row=len-1;
	var inputStr ="";
	for ( var i =1; i < len ; i++ ) {
		var text= obj.options[i].text;
		var value = obj.options[i].value;
		inputStr = inputStr +"<input type='hidden' name='role_id"+i+"' value='"+value+"'/>";
		
	}
	
	inputStr = inputStr + "<input type='hidden' name='rowCount' value='"+row+"'/>";
	
	temp_role.innerHTML = inputStr;
	form1.submit();
       }
       
/************************从一个下拉菜单增加到另一个下拉菜单的方法**********************/
function fromTo(obj1,obj2)
{
	if(obj1.selectedIndex==-1){
		alert("请选择相应的项目!");
	}
	else{	
		var len = obj2.length;
		var hasItemflag = false;
		var value1 = obj1.options[obj1.selectedIndex].value;
		
		var text1 = obj1.options[obj1.selectedIndex].text;
		if ( (value1 == "all")&& (text1 =="---选取所有角色---") ) {
			obj2.options[0]=new Option ("---选取所有角色---","have");
			for ( var i = 1 ;i < obj1.length ;i++ ) {
				obj2.options[i]=new Option (obj1.options[i].text,obj1.options[i].value);
			}
			return;	
		}
		//obj1.options[obj1.selectedIndex] = null;
		for ( var i = 0 ;i < obj2.length ;i++ ) {
			if ( ( obj2.options[i].text == text1 )&& (obj2.options[i].value =value1)) {
				alert ( "你选择的项目已经添加了,不能重复添加!" );
				hasItemflag = true;
				break;
			}
		} 
		if ( ! hasItemflag ) {
			
			obj2.options[len] = new Option(text1,value1);
		}
	}
}
/*****************************end******************************/
/************************从一个下拉菜单删除option方法**********************/
function removeOption (obj1)
{
	if(obj1.selectedIndex==-1){
		alert("请选择相应的项目!");
	}
	else{	
	var value1 = obj1.options[obj1.selectedIndex].value;
	var len=obj1.length	
		var text1 = obj1.options[obj1.selectedIndex].text;
		if ( (value1 == "have")&& (text1 =="---选取所有角色---") ) {
			
			for ( var i = 1 ;i < len ;i++ ) {
			        
				obj1.options[1]=null;
			}
			return;	
		}
		obj1.options[obj1.selectedIndex] = null;
	}
}
</script>
<LINK href="../css/css.css" rel=stylesheet>
<body leftmargin="0" topmargin="0">

<!--导航-->
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
       <tr>
		<td width="100%" height="20"  bgcolor="#eeeeee" class="p2">您当前所在的位置>>授与权限</td>
	   </tr>
       <tr>
          <td width="100%" height="2"> <img border="0" src="../images/spacer.gif" width="1" height="3"></td>
       </tr>
    </table>
<!--标题-->
  <div align="center">
   <table border="0" width="100%" cellspacing="0" cellpadding="0" height="34">
	<tr>
		<td width="159" background="../images/back_board2.gif" nowrap valign="bottom"><span class="title01">&nbsp;&nbsp;<span class="style1">授与权限</span></span></td>
		<td valign="bottom" align="right" width="642"></td>
	</tr>
	<tr>
		<td bgcolor="#2C9CC4" colspan="2"><img border="0" src="../images/bline_3.gif" width="1" height="2"></td>
	</tr>
</table>
</div><br>
<%
//String user_id=request.getAttribute("USER_ID")==null?request.getParameter("user_id"):(String)request.getAttribute("USER_ID");
//String user_name=request.getAttribute("USER_NAME")==null?request.getParameter("user_name"):(String)request.getAttribute("USER_NAME");
%>
<div align="center">
<table width="90%" border="0">
  <tr> 
    <td><strong>为用户“<%=user_name%>”授予角色</strong></td>
  </tr>
</table>
</div>

<form name="form1" method="post" action="user_role_modify_save.jsp">
  <input name="user_id" type="hidden" value="<%=user_id%>">
  <input name="user_name" type="hidden" value="<%=user_name%>">
  <table width="100%" border="0">
    <table width="80%" border="0" align="center">
      <tr>
        <td align="center">可授予的角色</td>
        <td align="center"></td>
        <td align="center">已授予的角色</td>
      </tr>
      <tr>
        <td align="center">
       
	   <select name="all_role" size="15" multiple>
	      <option value="all">---选取所有角色---</option>
	      <%
               //ResultSet2 rs=(ResultSet2)request.getAttribute("ALL_ROLE");
               while(rs.next()){
             %>
              <option value="<%=rs.getString("role_id")%>"><%=rs.getString("role_name")%></option>
              <%}%>
	   </select>
		</td>
        <td align="center">
            <br>
            <br>
            <br>
            <input type="button"  value="增加&gt;&gt;" class="denglu1"  onClick="fromTo(form1.all_role,form1.have_role)">
            <br>
            <br>
            <br>
            <input type="button"  value="&lt;&lt;删除" class="denglu1"  onClick="removeOption(form1.have_role)">
            <br>
            <br>
            <br>
        </td>
        <td align="center">
		 <select name="have_role" size="15" multiple>
		 <option value="have">---选取所有角色---</option>
          <%
               //ResultSet2 rs1=(ResultSet2)request.getAttribute("HAVE_ROLE");
               while(rs1.next()){
             %>
              <option value="<%=rs1.getString("role_id")%>"><%=rs1.getString("role_name")%></option>
              <%}%>
         </select>
		</td>
      </tr>
    </table>
    <table width="80%" border="0" align="center">
    <BR>
    <tr>
    <td></td>
    </tr>
    <tr> 
          <td align="center"> 
              <input type="button" name="Button22" value="保存" class="denglu1" onClick="save(form1.have_role)">
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input type="button" name="Button32" value="返回" class="denglu1"  onClick="javascript: window.history.back();">
          </td>
          <div display="true" id="temp_role">
      </tr>
    </table>
  </table>
</form>
</body>
</html>
