<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/easyui/icon.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/user-center-style.css' type='text/css' media='screen' />
<link rel="stylesheet" href="${ctx}/resources/js/multiselect/jquery.multiselect.css" type="text/css" />
<%@ include file="../../common/top.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/multiselect/jquery-ui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/multiselect/jquery.multiselect.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/jquery.checktable.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/uploadHandlers.js"></script>
<%@ include file="../../common/validation.jsp"%>
<title>命题教师管理</title>
<style>
.tongjiTab td{border:1px solid #999999;}
.errorTd{color: red;text-align: center;}
 .first{width: 100px;height: 25px;text-align: center;}
  .second{width: 280px;height: 25px; text-align: center;}
    #user-info{
         box-shadow: 0 0 6px #aaa;
    }
    .myTitleTd{
	font-size: 12px;
	font-weight: normal;
	width: 100px;
	height:25px;
	text-align: right;
}

.bookSelTable{
	font-size: 12px;
	font-weight: normal;
}

.myValueTd{
	font-size: 12px;
	font-weight: normal;
	text-align: left;
}

.myValueTd input[type=text]{
	width: 240px;
}


.myValueTd textarea{
	width: 200px;
	height: 50px;
}

.myValueTd select{
	width: 200px;
}

.myValueTd label{
	color: red;
}

.formErrorContent{
	display: none;
}
</style>
<script language="javascript">
$(document).ready(function(){
	
	$("#downLinkTemp").on('click',function(){
		window.location.href="${ctx}/resources/downloads/命题教师与课程关联关系导入模板.xlsx";
	});
	
	$("#downTeacherTemp").on('click',function(){
		window.location.href="${ctx}/resources/downloads/命题教师导入模板.xlsx";
	});
	
	$("#formForEdit").validationEngine();
	
    $('#search-form').submit(function(event){
        event.preventDefault(); 
        var param = $('#search-form').serializeJson();
        param = $.extend(param, {page:1,rows:20});
        $('#dg').datagrid('load',param);
    });
    
    $("#dg").datagrid({
        onDblClickRow: function (rowIndex, rowData) {
        	//openUserWin(rowData,"编辑用户");
        	editUser();
        }
    });
    
    $("#linkRolls").on('click',function(){
    	var rowData = $("#dg").datagrid('getSelected');
    	if(rowData){
    		openLinkRollsWin(rowData.id);
    	}else{
    		$.messager.alert('提示','请选择一行进行关联角色操作');
    	}
    });
    
    $("#linkSubjects").on('click',function(){
    	var rowData = $("#dg").datagrid('getSelected');
    	if(rowData){
    		openLinkSubjectWin(rowData.id);
    	}else{
    		$.messager.alert('提示','请选择一行进行关联课程操作');
    	}
    });
    
    
    $('#searchCourseBtn').on('click',function(){
        var param = {'keyword':$('#keywordForSearchCourse').val()};
        param = $.extend(param, {page:1,rows:10});
        $('#allSubjectDg').datagrid('load',param);
        return false;
    });
    
    $("#saveEditBtn").click(function(){
    	var gender=$("#genderForEdit").val();
    	var phone=$("#phoneForEdit").val();
    	var email=$("#emailForEdit").val();
    	//var userType=$("#userTypeForEdit").val();
    	//var id=$("#idForEdit").val();
    	//var email=$("#emailForEdit").val();
    	var flag=true;
    	var pattern = /^['男'|'女']$/ ;
    	if(gender!=""){
    		if(!pattern.test(gender)){
    			$.messager.alert('提示', "请输入性别男或女,或者置空!", 'error');
    			flag=false;
    			return false;
    		}
    	}
    	var re =  /^(1[0-9]{10})|(1[0-9]{10})|(1[0-9]{10})$/;

    	if(phone!=""){
    		if(!re.test(phone)){
    			$.messager.alert('提示', "请输入合法的电话号码!", 'error',function(){
    				$("#phoneForEdit").select();
    			});
    			flag=false;
    			return false;
    		}
    	}
    	
    	var res=/^[a-z0-9]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$/i;
    	if(email!=""){
    		if(!res.test(email)){
    			$.messager.alert('提示', "请输入合法Email,或者置空!", 'error',function(){
    				$("#emailForEdit").select();
    			});
    			flag=false;
    			return false;
    		}
    	}
    	if(flag){
    		saveUserEdit();
    	}
    	return false;
    });
    
    $("#saveLinkRollBtn").click(function(){
    	saveLinkRoll();
    	return false;
    });
    
    $("#saveLinkSubjectBtn").click(function(){
    	saveLinkSubject();
    	return false;
    });
    
    $("#cancleLinkRollBtn").on('click',function(){
    	$('#linkRollDiv').window('close');
    	return false;
    });
    
    $("#cancleEditBtn").on('click',function(){
    	$('#editUserDiv').window('close');
    	return false;
    });
    
    
    $("#cancleLinkSubjectBtn").on('click',function(){
    	$('#linkSubjectDiv').window('close');
    	return false;
    });
    
    $("#addRollBtn").on('click',function(){
    	var rows1 = $("#allRollDg").datagrid('getSelections');
    	for(var i=0;i<rows1.length;i++){
    		var index = -1;
    		var existed = ((index = $("#chosenRollDg").datagrid('getRowIndex',rows1[i])) >= 0);
    		if(!existed){
        		//rows1[i].inCourseStatus = ${defaultBookInCourseStatus}; 
        		index = $('#chosenRollDg').datagrid('insertRow',{row:rows1[i]}).datagrid('getRows').length-1;
        		$('#chosenRollDg').datagrid('beginEdit', index);
    		}
    		$('#chosenRollDg').datagrid('selectRow', index);
    	}
    	$("#allRollDg").datagrid('unselectAll');
    });
    
    $("#delRollBtn").click(function(){
    	var selectedRow = null;
    	while((selectedRow = $("#chosenRollDg").datagrid('getSelected')) != null){
    		var selectedIndex = $("#chosenRollDg").datagrid('getRowIndex',selectedRow);
    		$("#chosenRollDg").datagrid('deleteRow',selectedIndex);
    	}
    });
    
    
    $("#addSubjectBtn").on('click',function(){
    	dataToRight();
    });
    
    $("#delSubjectBtn").click(function(){
    	dataToLeft();
    });
});

function dataToLeft(){
	var selectedRow = null;
	while((selectedRow = $("#chosenSubjectDg").datagrid('getSelected')) != null){
		var selectedIndex = $("#chosenSubjectDg").datagrid('getRowIndex',selectedRow);
		$("#chosenSubjectDg").datagrid('deleteRow',selectedIndex);
	}
}
function dataToRight(){
	var data= $("#chosenSubjectDg").datagrid("getData");
	var rows1 = $("#allSubjectDg").datagrid('getSelections');
	var rows=data.rows;
	var code;
	var flag;
	for(var i=0;i<rows1.length;i++){
		code=rows1[i].code;
	}
	for(var i=0;i<rows.length;i++){
		if(rows[i].code==code){
			flag=true;
		}
	}
	if(!flag){
		for(var i=0;i<rows1.length;i++){
			code=rows1[i].code;
			var index = -1;
			var existed = ((index = $("#chosenSubjectDg").datagrid('getRowIndex',rows1[i])) >= 0);
			if(!existed){
	    		//rows1[i].inCourseStatus = ${defaultBookInCourseStatus};
	    		index = $('#chosenSubjectDg').datagrid('insertRow',{row:rows1[i]}).datagrid('getRows').length-1;
	    		$('#chosenSubjectDg').datagrid('beginEdit', index);
			}
			$('#chosenSubjectDg').datagrid('selectRow', index);
		}
		$("#allSubjectDg").datagrid('unselectAll');
	}
}
function saveUserEdit(){
	if($("#formForEdit").validationEngine('validate')){
		$.ajax({
			type : "POST",
			url : "${ctx}/user/validateLoginName",
			data : $('#formForEdit').serialize(), 
			success : function(callback) {
				if(callback.flag == 'success'){
					$.ajax({
						type : "POST",
						url : "${ctx}/user/save",
						data : $('#formForEdit').serialize(), 
						success : function(res) {
							if(res.flag == 'success'){
								$.messager.alert('提示', ($("#idForEdit").val() == ""?"新增":"修改") + "用户成功!", 'info', function () {
									$('#editUserDiv').window('close');
									$('#dg').datagrid('reload');
			                    });
							}else{
								$.messager.alert('提示', "更新失败，请刷新后操作!", 'error');
							}
						}
					});
				}else{
					$.messager.alert('提示', callback.msg, 'error',function(){
						$("#loginNameForEdit").select();
					});
				}
			}
		});
	}
}

function saveLinkRoll(){
	var rows = $('#chosenRollDg').datagrid('getRows');
	var arr = [];
	for(var i=0;i<rows.length;i++){
		arr[arr.length] = rows[i].id ;
	}
	var param = {'userId':$('#userIdForlinkRoll').val(),'links':arr};
	$.ajax({
		type : "POST",
		url : "${ctx}/user/saveLinkRoll",
		data : param,
		success : function(callback) {
			if(callback.flag == 'success'){
				$.messager.alert('提示', callback.msg, 'info', function () {
					$('#linkRollDiv').window('close');
					$('#dg').datagrid('reload');
                });
			}else{
				$.messager.alert('提示', "更新失败，请刷新后操作!", 'error');
			}
		}
	});
}


function saveLinkSubject(){
	var rows = $('#chosenSubjectDg').datagrid('getRows');
	var arr = [];
	for(var i=0;i<rows.length;i++){
		arr[arr.length] = rows[i].id ;
	}
	var param = {'userId':$('#userIdForlinkSubject').val(),'links':arr};
	$.ajax({
		type : "POST",
		url : "${ctx}/user/saveLinkSubject",
		data : param,
		success : function(callback) {
			if(callback.flag == 'success'){
				$.messager.alert('提示', callback.msg, 'info', function () {
					$('#linkSubjectDiv').window('close');
					$('#dg').datagrid('reload');
                });
			}else{
				$.messager.alert('提示', "更新失败，请刷新后操作!", 'error');
			}
		}
	});
}

function openLinkSubjectWin(userId){
	$("#userIdForlinkSubject").val(userId);
	$('#chosenSubjectDg').datagrid({
	    url:"${ctx}/course/getLinkSubject/" + userId,
	    onLoadSuccess:function(data){
	    	for(var i=0;i<data.total;i++){
	    		$('#chosenSubjectDg').datagrid('beginEdit', i);
	    	}
	    }
	});
	$('#linkSubjectDiv').window('open');
}

function openLinkRollsWin(userId){
	$("#userIdForlinkRoll").val(userId);
	$('#chosenRollDg').datagrid({
	    url:"${ctx}/user/getSelectRole/" + userId,
	    onLoadSuccess:function(data){
	    	for(var i=0;i<data.total;i++){
	    		$('#chosenRollsDg').datagrid('beginEdit', i);
	    	}
	    }
	});
	$('#linkRollDiv').window('open');
}

function addUser(){
	//window.location.href = "${ctx}/user/add";
	openUserWin({},"添加新用户");
}

function openUserWin(user,title){
	$("#roleLab").hide();
	$("#nameForEdit").val(user.name);
	$("#loginNameForEdit").val(user.loginName);
	$("#genderForEdit").val(user.gender);
	$("#positionForEdit").val(user.position);
	$("#schoolForEdit").val(user.school);
	$("#departmentForEdit").val(user.department);
	$("#phoneForEdit").val(user.phone);
	$("#emailForEdit").val(user.email);
	$("#idForEdit").val(user.id);
	$('#editUserDiv').window({"title":title});
	$('#editUserDiv').window('open');
}


function editUser(){
	var row = $('#dg').datagrid('getSelected');
    if (row){
        $("#role").combobox({
            url: '${ctx}/user/getEditRole/'+row.id,
            valueField: "id",
            textField: "name",
            panelHeight: "auto",
            method:'get',
            editable: false
        }); 
        
        openUserWin(row,"编辑用户");
    }
    else{
    	$.messager.alert('提示','请选择需要修改的用户');
    }
}
function activeUser(){
	var row = $('#dg').datagrid('getSelected');
	if(row.isEnabled!="1"){
		var obj={
				"id" :row.id	
			};
			var User = JSON.stringify(obj);
			 $.ajax({
					type : "POST",
					url : "${ctx}/user/updateStatus/active",
					data : User,
					contentType : "application/json; charset=utf-8",
					dataType : "json",
					success : function(callback) {
						callback = eval(callback);
						if(callback.type=="fail"){
							$.messager.alert('提示','操作失败');
						}else{
							var rowIndex = $('#dg').datagrid('getRowIndex',row);
				            $('#dg').datagrid('updateRow',{
				                index: rowIndex,
				                row: {isEnabled: 1}
				            });
						}
					}
				});
    }
}
function inactiveUser(){
	var row = $('#dg').datagrid('getSelected');
    if(row.isEnabled!="0"){
    	var obj={
			"id" :row.id	
		};
		var User = JSON.stringify(obj);
		 $.ajax({
				type : "POST",
				url : "${ctx}/user/updateStatus/inactive",
				data : User,
				contentType : "application/json; charset=utf-8",
				dataType : "json",
				success : function(callback) {
					callback = eval(callback);
					if(callback.type=="fail"){
						$.messager.alert('提示','操作失败');
					}else{
						 var rowIndex = $('#dg').datagrid('getRowIndex',row);
				            $('#dg').datagrid('updateRow',{
				                index: rowIndex,
				                row: {isEnabled: 0}
				            });

					}
				}
			});
    }
}

function resetStatus(){
	var row = $('#dg').datagrid('getSelected');
	 if (row){
		 var obj={
					"id" :row.id	 
				};
				var User = JSON.stringify(obj);
		 $.ajax({
				type : "POST",
				url : "${ctx}/user/resetPwd",
				data : User,
				contentType : "application/json; charset=utf-8",
				dataType : "json",
				success : function(callback) {
					callback = eval(callback);
					if(callback.type=="success"){
						$.messager.alert('提示','重置该用户密码成功!');
					}else{
						$.messager.alert('提示','重置该用户密码失败!');
					}
				}
			});
	 }else{
		 $.messager.alert('提示','请选择需要重置密码的用户');
	 }
	
}
function isEnabledFormatter(value,row,index){
	if(value==1){
		return "启用";
	}else{
		return "停用";
	}
}

function statusFormatter(value){
	if(value==0){
		return "启用";
	}else{
		return "停用";
	}
}
</script>
</head>
<body>
    <%@ include file="../../common/header.jsp"%>
    <div id="content" class="content">
        <%@ include file="../../common/sub_menu.jsp"%>
        <div class="page" id="page" >
        <div class="page-header" >命题教师管理</div>
        <div class="page-body">
	        <div class="right" style="min-height:300px;position: relative;">
	             <div id="list-wrap posts" class="listview">
	                 <table id="dg" class="easyui-datagrid"
	                     data-options="url:'${ctx}/teacher/queryUsers'
	                     ,toolbar: '#tb'
	                     ,fitColumns:true
	                     ,singleSelect:true
	                     ,striped:true
	                     ,pagination:true">
	                     <thead>
	                         <tr class="title">
	                             <th data-options="field:'id',width:40">ID</th>
	                             <th data-options="field:'loginName',width:80">登录名</th>
	                             <th data-options="field:'name',width:90">姓名</th>
	                             <th data-options="field:'gender',width:40">性别</th>
	                             <th data-options="field:'position',width:100">职称</th>
	                             <th data-options="field:'school',width:100">单位</th>
	                             <th data-options="field:'department',width:100">院系</th>
	                             <th data-options="field:'phone',width:90">电话</th>
	                             <th data-options="field:'courseString',width:150">课程</th>
	                             <th data-options="field:'isEnabled',width:50,
	                                   formatter: isEnabledFormatter">状态</th>
	                         </tr>
	                     </thead>
	                   </table>
	                   
	                   <div id="tb" style="height:auto">
		                   <div >
	                            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="addUser()">添加</a>
	                            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="editUser()">编辑</a>
	                            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-confirm',plain:true" onclick="activeUser()">启用</a>
	                            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-no',plain:true" onclick="inactiveUser()">停用</a>
	                            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="resetStatus()">重置密码</a>
	                            <!--  <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-import-plan',plain:true" id="linkRolls">关联角色</a>-->
	                            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-import-plan',plain:true" id="linkSubjects">关联课程</a>
	                            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-import-plan',plain:true" id="importTeacher">导入命题教师</a>
	                            <a href="#" class="easyui-linkbutton" iconCls="icon-download" id="downTeacherTemp">下载命题教师模板</a>
	                            <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-import-plan',plain:true" id="importTeacherLinkCourse">导入命题教师与课程关联关系</a>
	                            <a href="#" class="easyui-linkbutton" iconCls="icon-download" id="downLinkTemp">下载关联模板</a>
	                        </div>
	                        
	                        <div>
					            <form id="search-form" method="post" >
						            &nbsp;&nbsp;<label>课程：</label><input name="course" placeholder="课程名称或编号"/>
						            &nbsp;&nbsp;<label>姓名：</label><input name="keyword" type="text" placeholder="姓名" />
						            <button id="searchBtn">查询</button>
					            </form>
							</div>
						</div>
	               </div>
	            </div>
	            
	            
	            
	            
<div style="display: none;">
	            <div id="linkRollDiv" title="关联角色" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:660px;height:340px;padding:5px;overflow-x: hidden;">
			    	<div id="barcode-scan" style="font-size: 12px;">
			    		<form action="#" id="formForlinkRoll">
			    			<input type="hidden" name="userId" id="userIdForlinkRoll"/>
			    			<table style="width: 630px;margin-top: 5px;" cellpadding="0" border="0" class="bookSelTable" align="center">
			    				<tr>
			    					<td>
										<table id="allRollDg" class="easyui-datagrid" style="width:300px;height:240px;" data-options="url:'${ctx}/user/getLinkRole',fitColumns:true,singleSelect:false,pagination:true">
			    							<thead>
										        <tr>
										        	<th data-options="field:'id',width:60">id</th>
										            <th data-options="field:'name',width:150">名称</th>
										            <!-- <th data-options="field:'isEnabled',width:60,formatter: isEnabledFormatter">状态</th>-->
										        </tr>   
			    							</thead>
										</table>
									</td>
									<td valign="middle" align="center">
										<div style="margin-bottom: 30px;">
											<input type="button" value="&gt;" style="width: 30px;" id="addRollBtn"/>
										</div>
										<div>
											<input type="button" value="&lt;" style="width: 30px;" id="delRollBtn"/>
										</div>
									</td>
									
									<td align="right" valign="bottom">
										<table id="chosenRollDg" class="easyui-datagrid" style="width:250px;height:240px" data-options="fitColumns:true,singleSelect:false">
										    <thead>   
										        <tr>
										            <th data-options="field:'id',width:100">id</th>
										            <th data-options="field:'name',width:150">名称</th>
										            <!--  <th data-options="field:'isEnabled',width:80,formatter: statusFormatter">状态</th>-->
										        </tr>   
										    </thead>   
										</table>
									</td>
			    				</tr>
			    				<tr>
									<td colspan="3" style="padding-top: 10px;" align="center"><button style="margin-right: 50px;" id="saveLinkRollBtn">保存</button><button id="cancleLinkRollBtn">取消</button></td>
								</tr>
			    			</table>
			    		</form>
			    	</div>
			    </div>
			    
			    <div id="linkSubjectDiv" title="关联课程" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:675px;height:370px;padding:5px;overflow-x: hidden;">
			    	<div id="barcode-scan" style="font-size: 12px;">
			    		<form action="#" id="formForlinkSubject">
			    			<input type="hidden" name="userId" id="userIdForlinkSubject"/>
			    			<table style="width: 630px;margin-top: 5px;" cellpadding="0" border="0" class="bookSelTable" align="center">
			    				<tr>
			    					<td>
			    						<div style="text-align: left;">
											<input id="keywordForSearchCourse" placeholder="课程名称或编号"/>
											<button id="searchCourseBtn">查询</button>
										</div>
										<table id="allSubjectDg" class="easyui-datagrid" style="width:320px;height:240px;" data-options="url:'${ctx}/user/getAllSubject',fitColumns:true,singleSelect:true,pagination:true,onClickRow:dataToRight">
			    							<thead>
										        <tr>
										        	<th data-options="field:'code',width:60">code</th>
										            <th data-options="field:'name',width:150">名称</th>
										            <!-- <th data-options="field:'isEnabled',width:60,formatter: isEnabledFormatter">状态</th>-->
										        </tr>   
			    							</thead>
										</table>
									</td>
									<td valign="middle" align="center">
										<div style="margin-bottom: 30px;">
											<input type="button" value="&gt;" style="width: 30px;" id="addSubjectBtn"/>
										</div>
										<div>
											<input type="button" value="&lt;" style="width: 30px;" id="delSubjectBtn"/>
										</div>
									</td>
									
									<td align="right" valign="bottom">
										<table id="chosenSubjectDg" class="easyui-datagrid" style="width:250px;height:240px" data-options="fitColumns:true,singleSelect:true,onClickRow:dataToLeft">
										    <thead>   
										        <tr>
										            <th data-options="field:'code',width:100">code</th>
										            <th data-options="field:'name',width:150">名称</th>
										            <!--  <th data-options="field:'isEnabled',width:80,formatter: statusFormatter">状态</th>-->
										        </tr>   
										    </thead>   
										</table>
									</td>
			    				</tr>
			    				<tr>
									<td colspan="3" style="padding-top: 10px;" align="center"><button style="margin-right: 50px;" id="saveLinkSubjectBtn">保存</button><button id="cancleLinkSubjectBtn">取消</button></td>
								</tr>
			    			</table>
			    		</form>
			    	</div>
			    </div>
			    
			    
			    <div id="editUserDiv" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:450px;height:420px;padding:5px;overflow-x: hidden;">
			        <div id="barcode-scan" style="font-size: 12px;">
			        	<form action="#" id="formForEdit">
			        		<input type="hidden" name="id" id="idForEdit"/>
				            <table style="width: 450px; " cellpadding="5" >
				            	<tr>
				            		<td class="myTitleTd">登录名</td>
				            		<td class="myValueTd"><input type="text" name="loginName" id="loginNameForEdit" maxlength="40" class="validate[required]"/><label>*</label></td>
				            	</tr>
				            	<tr>
				            		<td class="myTitleTd">用户类型</td>
				            		<td class="myValueTd"><select name="userType" id="userTypeForEdit" style="width: 240px;"><option value="10">命题教师</option><option value="11">学科秘书</option><option value="12">录入员</option></select>
				            	</tr>
				            	<tr>
				            		<td class="myTitleTd">用户姓名</td>
				            		<td class="myValueTd"><input type="text" name="name" id="nameForEdit" maxlength="40" class="validate[required]"/><label>*</label></td>
				            	</tr>
				            	<tr>
				            		<td class="myTitleTd">性别</td>
				            		<td class="myValueTd"><select name="gender" id="genderForEdit" style="width: 240px;"><option value="">请选择</option><option value="男">男</option><option value="女">女</option></select></td>
				            	</tr>
				            	<tr>
				            		<td class="myTitleTd">职称</td>
				            		<td class="myValueTd"><input type="text" name="position" id="positionForEdit" /></td>
				            	</tr>
				            	<tr>
				            		<td class="myTitleTd">单位</td>
				            		<td class="myValueTd"><input type="text" name="school" id="schoolForEdit"/></td>
				            	</tr>
				            	<tr>
				            		<td class="myTitleTd">院系</td>
				            		<td class="myValueTd"><input type="text" name="department" id="departmentForEdit" /></td>
				            	</tr>
				            	<tr>
				            		<td class="myTitleTd">电话</td>
				            		<td class="myValueTd"><input type="text" name="phone" id="phoneForEdit" maxlength="11"/></td>
				            	</tr>
				            	<tr>
				            		<td class="myTitleTd">Email</td>
				            		<td class="myValueTd"><input type="text" name="email" id="emailForEdit" /></td>
				            	</tr>
				            	<tbody style="display: none;">
				            	<tr>
				            		<td class="myTitleTd" >关联角色</td>
				            		<td class="myValueTd"><input type="hidden" name="userType" value="10"/><input type="text"  id="emailForEdit"  value="普通用户" disabled="disabled"/></td>
				            	</tr>
				            	</tbody>
				            	<tr>
				            		<td colspan="2" align="center"><button style="margin-right: 50px;" id="saveEditBtn">保存</button><button id="cancleEditBtn">取消</button></td>
				            	</tr>
				            </table>
			            </form>
			        </div>
			    </div>
			    
	        </div>
        </div>
    </div>
</div>

<div id="importTeacherDiv" title="导入命题教师" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:500px;height:300px;padding:10px;">
			<div style="display: inline;   padding: 2px;">
				<span id="spanButtonPlaceholder"></span> 
				<div style="padding-top: 25px;" >
				  	<div id="successTeacher" style="display:none;"></div>
				  	
					  <div id="errorTeacher" style="display:none;">
					  	<div><span>数据存在错误信息:</span></div>
				        <table style="border-collapse: collapse;" class="tongjiTab" >
				        	<tr>
				        		<td class="first">行号</td>
				        		<td class="second">错误信息</td>
				        	</tr>
				        	<tr>
				        		<td id="firstTeacher" class="errorTd"></td>
				        		<td id="secondTeacher" class="errorTd"></td>
				        	</tr>
				        </table>
	    			</div>
    			</div>
			</div>
		</div>
		
<div id="importTeacherLinkCourseDiv" title="导入命题教师与课程关联关系" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:500px;height:300px;padding:10px;">
			<div style="display: inline;   padding: 2px;">
				<span id="spanButtonPlaceholder"></span> 
				<div style="padding-top: 25px;" >
				  	<div id="successTeacherLinkCourse" style="display:none;"></div>
				  	
					  <div id="errorTeacherLinkCourse" style="display:none;">
					  	<div><span>行数据存在错误信息:</span></div>
				        <table style="border-collapse: collapse;" class="tongjiTab" id="importUserCourseMsgTable">
				        	<tr>
				        		<td class="first">行号</td>
				        		<td class="second">错误信息</td>
				        	</tr>
				        	<tr>
				        		<td id="firstTeacherLinkCourse" class="errorTd"></td>
				        		<td id="secondTeacherLinkCourse" class="errorTd"></td>
				        	</tr>
				        </table>
	    			</div>
    			</div>
			</div>
		</div>
</body>
</html>


<script type="text/javascript">
$(function(){
	loadSwfUpload();	//首先加载swfupload();
	
	loadSwfUpload1();
	
	$("#importTeacher").on('click',function(){
		$("#importTeacherDiv").window('open');
		$("#errorTeacher").hide();
		$("#successTeacher").hide();
	});
	$("#importTeacherLinkCourse").on('click',function(){
		$("#importTeacherLinkCourseDiv").window('open');
		$("#successTeacherLinkCourse").hide();
		$("#errorTeacherLinkCourse").hide();
	});
});
var swfUpload = null;
var swfUpload1= null;
function loadSwfUpload() {
	swfUpload = new SWFUpload({
		 upload_url :"${ctx}/attachment/upload",
		 post_params: {"userId":"${sessionScope.web_session_user.id}"},
		 use_query_string : false,
		  
		// File Upload Settings
		file_size_limit : "50 MB",	// 50MB
		file_types : "*.xls;*.xlsx",
		file_types_description : "Excel文件",
		file_upload_limit 	:	0,

		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,//选择好文件后提交
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		
		// Button Settings
		button_image_url : '${ctx}/resources/images/SmallSpyGlassWithTransperancy_17x18.png',
		button_placeholder_id : "spanButtonPlaceholder",
		button_width: 180,
		button_height: 18,
		button_text : '<span class="button">导入命题教师<span class="buttonSmall"></span></span>',
		button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12px; } .buttonSmall { font-size: 10px; color: #ff0000;}',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,
		
		
		// Flash Settings
		flash_url : '${ctx}/resources/js/swfupload/swfupload.swf',

		custom_settings : {
			upload_target : "importDivFileProgressContainer"
		},
		// Debug Settings
		debug: false //是否显示调试窗口
	});
};


function loadSwfUpload1() {
	swfUpload = new SWFUpload({
		 upload_url :"${ctx}/attachment/upload",
		 post_params: {"userId":"${sessionScope.web_session_user.id}"},
		 use_query_string : false,
		  
		// File Upload Settings
		file_size_limit : "50 MB",	// 50MB
		file_types : "*.xls;*.xlsx",
		file_types_description : "Excel文件",
		file_upload_limit 	:	0,

		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,//选择好文件后提交
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess1,
		upload_complete_handler : uploadComplete,
		
		// Button Settings
		button_image_url : '${ctx}/resources/images/SmallSpyGlassWithTransperancy_17x18.png',
		button_placeholder_id : "spanButtonPlaceholder",
		button_width: 180,
		button_height: 18,
		button_text : '<span class="button">导入命题教师与课程关联关系<span class="buttonSmall"></span></span>',
		button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12px; } .buttonSmall { font-size: 10px; color: #ff0000;}',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,
		
		
		// Flash Settings
		flash_url : '${ctx}/resources/js/swfupload/swfupload.swf',

		custom_settings : {
			upload_target : "importDivFileProgressContainer"
		},
		// Debug Settings
		debug: false //是否显示调试窗口
	});
};

function uploadSuccess(file, serverData) {
	serverData=eval('(' + serverData + ')');
	if(serverData.flag=='success'){
		//文件信息保存到数据库后需要对文件进行解析处理
		var param={
				"attId":serverData.att.id
		}
		
		$.ajax({
			type : "POST",
			url : "${ctx}/user/upLoadUser",
			data : param,
			dataType : "json",
			success : function(res) {
				$(document).unmask();
				if(res.result=='fail'){ 
					$("#firstTeacher").html(res.lineNum);
					$("#secondTeacher").html(res.msg);
					$("#errorTeacher").show();
				}else if(res.result=='success'){
					$("#successTeacher").html("成功导入"+res.successNum+"条记录");
					$("#successTeacher").show();
					$("#errorTeacher").hide();
					$('#dg').datagrid('reload');
				}else{
					$("#firstTeacher").html("-");
					$("#secondTeacher").html(res.msg);
					$("#errorTeacher").show();
				}
			}
		});
	}else{
		$(document).unmask();
		$.messager.alert('提示',serverData.msg,'error');
	}
}

function uploadSuccess1(file, serverData) {
	serverData=eval('(' + serverData + ')');
	if(serverData.flag=='success'){
		//文件信息保存到数据库后需要对文件进行解析处理
		var param={
				"attId":serverData.att.id
		}
		
		$.ajax({
			type : "POST",
			url : "${ctx}/user/upLoadUserCourse",
			data : param,
			dataType : "json",
			success : function(res) {
				$(document).unmask();
				if(res.result=='fail'){ 
					$("#firstTeacherLinkCourse").html(res.lineNum);
					$("#secondTeacherLinkCourse").html(res.msg);
					$("#errorTeacherLinkCourse").show();
				}else if(res.result=='success'){
					$("#successTeacherLinkCourse").html("成功导入"+res.successNum+"条记录");
					$("#successTeacherLinkCourse").show();
					$("#errorTeacherLinkCourse").hide();
					$('#dg').datagrid('reload');
				}else{
					$("#firstTeacherLinkCourse").html("-");
					$("#secondTeacherLinkCourse").html(res.msg);
					$("#errorTeacherLinkCourse").show();
				}
			}
		});
		
	}else{
		$(document).unmask();
		$.messager.alert('提示',serverData.msg,'error');
	}
}
</script>
