
<%@ page autoeventwireup="false" inherits="WebExam.Web.apyj, App_Web_plgfti2c" language="vb" masterpagefile="~/Page.master" title="安排阅卷" %>

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="mainCopy">

    <script type="text/javascript">
// <!CDATA[
  var groupXML=new ActiveXObject ("Microsoft.XMLDOM");//小组人员情况
		   groupXML.async = false
		   groupXML.load("groupmem.aspx"+window.location.search)
		   var groupNodes  =groupXML.selectNodes("/NewDataSet/checkerGroup")

		   var groupAssignXML=new ActiveXObject ("Microsoft.XMLDOM");//小组分配情况
		   groupAssignXML.async = false
		   groupAssignXML.load("groupassign.aspx"+window.location.search);
		  
		   var groupAssignNodes  =groupAssignXML.selectNodes("/group/test")
		   
		   
function OnExpertMenuDataReadyStateChange()
{
	if(typeof(ExpertXML)=="undefined")return;
	
	if(ExpertXSL.XMLDocument.readyState<4||ExpertXML.XMLDocument.readyState<4)
		return;
	
	onload();
	
}
function delGroup(No){//删除阅卷小组
   if (!confirm("确定要删除该阅卷小组吗？")) return
  var groups=groupDiv.all.tags('select')
  var groupsLength=groups.length
  var code=""
  var j=1
  n1:
  for(var i=0;i<groupsLength;i++)
  {  if (i==No-1)
     continue n1
    
     code+="编号"+j
     code+="<select id='group_"+j+"'>"
     code+=groups[i].innerHTML
     code+="</select>"
     code+="<a href=\"javascript:add('"+j+"')\">增加人员</a> "
     code+="<a href=\"javascript:del('"+j+"')\">删除人员</a> "
     code+="<a href='javascript:delGroup("+j+")'>删除小组</a><input type='hidden' name='ul_"+j+"'><br>"
     j++
     
  }
  groupDiv.innerHTML=code
  
   var allSelect=document.forms[0].getElementsByTagName("select")
    for (var i=0;i<allSelect.length;i++)
    { var selName=allSelect[i].name
    
      if (selName.substring(0,6)=="keyid_")
      {
        var ulo=eval("document.forms[0]."+selName)
        var sl=ulo.selectedIndex
        
       // if (sl==-1) return
        ulo.remove(eval(No)-1)
        for (var ii=No-1;ii<ulo.length;ii++)
        {
          ulo(ii).value=eval(ulo(ii).value)-1
          ulo(ii).text=eval(ulo(ii).text)-1
        }
        ulo.selectedIndex=sl
      }
    }  
}
function addGroup(){//增加阅卷小组
    var groups=groupDiv.all.tags('select')
    var groupsLength=groups.length
    var No
    if (groupsLength==0)
    No=1
    else
    No=eval(groups[groupsLength-1].id.substring(6))+1
   
    var groupCode
    groupCode="编号"+No

 	groupCode+="<select id='group_"+No+"'>"
    //groupCode+="<option>vvvaaaa</option>"
     
    groupCode+="</select>"
 	        
    groupCode+="<a href=\"javascript:add('"+No+"')\">增加人员</a> "
    groupCode+="<a href=\"javascript:del('"+No+"')\">删除人员</a> "
 	groupCode+="<a href='javascript:delGroup("+No+")'>删除小组</a><input type='hidden' name='ul_"+No+"'><br>"
 	
    groupDiv.innerHTML+=groupCode
    
    
    var allSelect=document.forms[0].getElementsByTagName("select")
    for (var i=0;i<allSelect.length;i++)
    { var selName=allSelect[i].name
    
      if (selName.substring(0,6)=="keyid_")
      {
        var ulo=eval("document.forms[0]."+selName)

        var oOption = document.createElement("OPTION");
        ulo.options.add(oOption);
        oOption.innerText = No;
        oOption.value = No;
        
      }
    }
    
}
function add(keyid){

  //var allslo=document.forms[0].getElementsByTagName("select")
  var addUser=true
  var arr = showModalDialog("../../department/users/allusers.htm?o=0&type=partforexaminer", "", "dialogHeight:540px;dialogWidth:630px;help:0; status:0");
 
  if (arr==null) return;
  var tmp;
  tmp=arr[0];
  var tl=tmp.length
  var ulo=eval("document.forms[0].group_"+keyid)
 // var con=false
 //for (var j=0;j<allslo.length;j++)
 //{ if (ulo==allslo[j])
 //  con=true
 //  if (con){
  for (var i=0;i<tl;i++)
  {addUser=true
  //检查该用户是否已经存在
    var allSelect=document.forms[0].getElementsByTagName("select")
    for (var ii=0;ii<allSelect.length;ii++)
    { var selName
      
      selName=allSelect[ii].id
      
      if (selName.substring(0,6)=="group_")
      {
        var ulo2=eval("document.forms[0]."+selName)
        for (var ij=0;ij<ulo2.length;ij++)
        {
        var oOption2 = ulo2(ij).text;
        if (tmp[i]==oOption2)
         {
          alert(oOption2+"用户已经存在，不再添加！")
          addUser=false
          break
         }
        }
      }
    }
  
  //结束检查
  
  
  if (addUser)
  {
  var oOption = document.createElement("OPTION");
  ulo.options.add(oOption);
  oOption.innerText = tmp[i];
  oOption.value = tmp[i];
  }
  }
  //}
// }

}
                           


function del(keyid){
 if (!confirm("确定要删除左侧下拉菜单中选中用户的阅卷任务吗？")) return
 var ulo=eval("document.forms[0].group_"+keyid)
 var sl=ulo.selectedIndex
 if (sl==-1) return
 ulo.remove(sl)
 ulo.selectedIndex=0
}
function btnconfirm_onclick() {
if (!(confirm("确定吗？")))return false;
var allTo=document.forms[0].getElementsByTagName("input")
var con=false
var ii=1
for (var j=0;j<allTo.length;j++)
 {
  try
   {
    if(allTo[j].name.substring(0,3)=="ul_")
    { var nn=allTo[j].name.substring(3)
      nn=nn.substring(0,nn.indexOf("_"))
            
     //
      var tt=eval("document.forms[0].group_"+ii)
      ii+=1
      var ll=tt.options.length
      var s="";con=false
      for (var i=0;i<ll;i++)
      {
      s+=","+tt.options[i].value
      con=true
      }
     allTo[j].value=s.substring(1)
    }
   }
  catch(e)
  {}
 }

 if (con) return true;
 else
 {alert("某些阅卷小组没有阅卷人员，请重新安排");return false;}
}

function onload() {
if(ExpertXSL.XMLDocument.readyState<4||ExpertXML.XMLDocument.readyState<4)
return 

var xml=groupAssignXML;
	var xsl=ExpertXSL.XMLDocument;
	var html="";
	try{
		html=xml.transformNode(xsl);
	}
	catch(x){//alert(ExpertXML.parseError.errorCode)
		return;
	}
	
	DivInsertMenu.insertAdjacentHTML("BeforeEnd",html);


     groupDiv.innerHTML=""
     var groupCode=""
     var groupArr
     var groupList=""
     for (var i=0;i<groupNodes.length;i++)
		   {  
		      var No=groupNodes[i].selectSingleNode("groupNo").text
		      groupList+=","+No
		   }
		  
		 
		   groupArr=groupList.substring(1).split(",")
		   var max=0
		   for (var i=0;i<groupArr.length;i++)
		   {
		     if (groupArr[i]>max) max=groupArr[i]
		   
		   
		   }
		   for (var i=0;i<max;i++)
		   { var No=i+1
		     
              groupCode+="编号"+No

 	          groupCode+="<select id='group_"+No+"'>"
              
              groupCode+="</select>"
 	        
              groupCode+="<a href=\"javascript:add('"+No+"')\">增加人员</a> "
              groupCode+="<a href=\"javascript:del('"+No+"')\">删除人员</a> "
 	          groupCode+="<a href='javascript:delGroup("+No+")'>删除小组</a><input type='hidden' name='ul_"+No+"'><br>"
		 
		    
		   for (var ii=0;ii<groupAssignNodes.length;ii++){ 
 
             var keyid=groupAssignNodes[ii].getAttribute("class")+groupAssignNodes[ii].getAttribute("testId");
             var groupNo=groupAssignNodes[ii].getAttribute("groupNo");
             var selObj
            
             var str="document.forms[0].keyid_"+keyid
	         selObj=eval(str)
	         
	         var oOption = document.createElement("OPTION");
              selObj.options.add(oOption);
              
              oOption.innerText = No;
              oOption.value = No;
	
	
	
	     }
		   
		   }
		   
		    groupDiv.innerHTML=groupCode 
		   
		    for (var i=0;i<groupNodes.length;i++){ 
		   
		      var userid=groupNodes[i].selectSingleNode("userid").text
		      var groupNo=groupNodes[i].selectSingleNode("groupNo").text
		      var selObj
		      selObj=eval("document.forms[0].group_"+groupNo)
		     
		      var oOption = document.createElement("OPTION");
              selObj.options.add(oOption);
              oOption.innerText = userid;
              oOption.value = userid;
		      
		   
		   }

 for (var i=0;i<groupAssignNodes.length;i++){ 

    var keyid=groupAssignNodes[i].getAttribute("class")+groupAssignNodes[i].getAttribute("testId");
    var groupNo=groupAssignNodes[i].getAttribute("groupId");
    var selObj

    var str="document.forms[0].keyid_"+keyid
   
	selObj=eval(str)

	selObj.selectedIndex=eval(groupNo)-1

	}
 
		   
}
// ]]>
    </script>

    <table align="center" border="0" cellpadding="0" cellspacing="0" style="width: 770px">
        <tr>
            <td valign="top">
                <div id="DivInsertMenu" class="editpaper">
                </div>
                <xml id="ExpertXSL" onreadystatechange="OnExpertMenuDataReadyStateChange()" src="../../../webxslt/paperkey.xslt"></xml>
                <xml id="ExpertXML" onreadystatechange="OnExpertMenuDataReadyStateChange()" src=""></xml>
            </td>
        </tr>
        <tr>
            <td>
                <p align="center">
                    <asp:Button ID="btnconfirm" runat="server" Text="确定" />
                  </p>
            </td>
        </tr>
        <tr>
            <td>
                <font face="宋体">建议：尽量减少每一阅卷小组内的人数，尽量使每一阅卷小组审阅最少数量的试题。比如，每一阅卷小组只有一人，每一阅卷小组只阅一题。</font></td>
        </tr>
    </table>
    <script type ="text/javascript" >onload()</script>
</asp:Content>
   
