<%--
  - kName   : UserList.jsp
  - Author(s)  : gyeongmo an
  - Date       : 2014.06.18
  - Copyright  : Copyright (c) 2014 www.udapsoft.co.kr, Inc.
  - Description: 사용자 관리
  --%>
  
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="kr.co.udapsoft.common.code.*" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ include file="/jsp/work/taglib.jsp" %>
<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />
<%
    ctx.init(request, response);
    HandlerStorage storage = ctx.getHandlerStorage();
    ValueObject params = storage.getParams();
    ValueObject user = storage.getUser();
    String event = storage.getEvent();
    RowSet rowSet = storage.getRowSet("ROWSET");
    RowSet acctTypeRowSet = storage.getRowSet("AcctTypeRowSet"); //계정 타입
    

    
%>
<SCRIPT language="JavaScript">
	/*예약함수*/
	var sheet1;
	var sheet1Row;
	var sheet1PageNo = 1;
	var pageLastRowIndex = 1;
	var validationResult = false;
	var filterShow = false;
	
	function _onReady(){
		gridInit(sheet1);

		jQuery("#btnSearch").click(function() {
			jQuery("#fevent").val("GET_USER_LIST");
			var url = Modular.model.PageContext.CONTEXT_ROOT + "/sycs/user/UserList_data.screen";
			Modular.view.IBSheet7.doSearch(sheet1, url, jQuery("#form1"), 10, "");
		});
		
		jQuery("#btnClear").click(function() {
			jQuery("#dept_cd2").val("");
			jQuery("#dept_nm2").val("");
			jQuery("#p_dept_cd").val("");
			jQuery("#p_dept_nm").val("");
			jQuery("#p_acct_type_id").val("");
			jQuery("#user_sabun").val("");
			jQuery("#user_name").val("");
		});
		
		jQuery("#btnAdd").click(function() {
			jQuery("#fevent").val("UserForm_Reg");
			jQuery("#form1").attr("action", "/sycs/user/UserForm.screen");
			jQuery("#form1").attr("target", "_self");
			jQuery("#form1").attr("method", "post");
			jQuery("#form1").submit();			
			
		});
		
		jQuery("#btnSync").click(function() {
			if(confirm("EHR데이타를 동기화 하시겠습니까?")){
				submitXmlRequest("/sycs/user/UserList_form.screen", "GET_EHR_DATA", document.form1);
			}			
		});
		
		jQuery("#btnExcel").click(function() {
			if(sheet1.RowCount() == 0) {
				alert("내역이 없습니다.");
				return;
			}
			var params = { FileName : "UserList.xls",  SheetName : "UserList", SheetDesign:0, Merge:1, DownCols:"no|user_sabun|user_name|buseo_nm|assigned_dept|position_name"+
					"|right_name|tel_no|hand_tel_no|e_mail|cre_date", TitleText:"사용자 관리", UserMerge:"0,0,1,10", AutoSizeColumn:1  } ;
			sheet1.Down2Excel(params);
		});
		
		sheet1.SetActionMenu("ExcelDown");
		autoResize();
	}
	
	function gridInit(sheetName){
		var init_sheet = {};
		init_sheet.Cfg = {SearchMode:2, Page:10};
		init_sheet.Cols = [
		       			{Header:'삭제',				Type:"DelCheck",		SaveName:"DEL_CHECK", 		Width:50, 	Align:"Center",	Hidden:"True"},
		    			{Header:'상태',			Type:"Status", 			SaveName:"STATUS", 			Width:0, 	Align:"Center",	Hidden:"True"},
		    			{Header:'번호',				Type:"Seq", 			SaveName:"NO",				Width:80, 	Align:"Center"},
		    			{Header:'☞사원번호',		Type:"Text", 			SaveName:"user_sabun", 		Width:100,	Align:"Center", Cursor:"Pointer"},
		    			{Header:'비밀번호',			Type:"Text", 			SaveName:"user_pw", 		Width:0, 	Align:"Center", Hidden:"True"},
		    			{Header:'☞ 이름',			Type:"Text", 			SaveName:"user_name", 		Width:120, 	Align:"Center", Cursor:"Pointer"},
		    			{Header:'부서',		Type:"Text",	 		SaveName:"buseo_nm", 		Width:120, 	Align:"Left"},
		    			{Header:'투입프로젝트',		Type:"Text", 			SaveName:"assigned_dept", 		Width:150, 	Align:"Left"},
		    			{Header:'직위',			Type:"Text", 			SaveName:"position_name", 		Width:100, 	Align:"Center"},
		    			{Header:'권한',		Type:"Text", 			SaveName:"right_name", 		Width:120, 	Align:"Center"},
		    			{Header:'계정타입',		Type:"Text", 			SaveName:"acct_type_name", 		Width:60, 	Align:"Center"},
		    			{Header:'전화번호',			Type:"Text", 			SaveName:"tel_no", 			Width:100, 	Align:"Center"},
		    			{Header:'휴대폰번호',		Type:"Text", 			SaveName:"hand_tel_no", 	Width:100, 	Align:"Center"},
		    			{Header:'E-mail',			Type:"Text", 			SaveName:"e_mail", 			Width:120, 	Align:"Left"},
		    			{Header:'등록일자',		Type:"Text", 			SaveName:"cre_date", 		Width:100, 	Align:"Center"},
		    			{Header:'계정ID',			Type:"Text", 			SaveName:"acct_id", 		Width:0, 	Align:"Left", Hidden:"True"}
		];

		init_sheet.HeaderMode = {Sort:1};
		IBS_InitSheet(sheetName, init_sheet);
		sheetName.SetDataAutoTrim(0);
		sheetName.SetEditable(false);
		
		setGridSize();
	}

	function sheet1_OnSearchEnd(code, message) {
	    if(code == 0) {
	    	setGridSize();
	    	sheet1.SetColFontColor("user_sabun", "#0000ff");
	    	sheet1.SetColFontColor("user_name", "#0000ff");
		} else {
			alert(message);
		}
	}
	
	function setGridSize() {
		sheet1.FitColWidth();
	}
	
	 function sheet1_OnDblClick(Row, Col, Value, CellX, CellY, CellW, CellH) {
		if (sheet1.ColSaveName(Col) == "user_name") {
			jQuery("#acct_id").val(sheet1.GetCellValue(Row, "acct_id"));
			jQuery("#fevent").val("GET_USERFORM_LIST");
			jQuery("#form1").attr("action", "/sycs/user/UserForm.screen");
			jQuery("#form1").attr("target", "_self");
			jQuery("#form1").attr("method", "post");
			jQuery("#form1").submit();
		}
		else if(sheet1.ColSaveName(Col) =="user_sabun"){
	        var user_sabun	= sheet1.GetCellValue(Row, "user_sabun");        
	        var user_pw	= sheet1.GetCellValue(Row, "user_pw");         
	    	f_gologin(user_sabun, user_pw );
		}
		else{
			return;	
		}
	 }

	//인사 정보 호출
	function getEhr(){
		if ( confirm("EHR데이타를 동기화 하시겠습니까?") ) {
			submitXmlRequest("/sycs/user/UserList_form.screen", "GET_EHR_DATA", document.form1);
		}
	}
	
	//자동로그인 기능
	function f_gologin(login_id,login_pw){
		var f = document.form1;
		if('<%= user.get("ACCT_TYPE_CODE")%>' != "ADMIN"){
			alert("관리자로 로그인한 사용자만 자동로그인 할수있습니다.");
			return;
		}
	
		f.login_id.value = login_id;
		f.login_pw.value = login_pw;
	
		if( !submitXmlRequest("/sign_on_check", "", f) ) {
			alert("로그인중입니다..");
		};
	}

	function doResult(resultObj) {
		try {
			if( resultObj.getRequestEvent() == "" ) {
				if( resultObj.getSuccess() ) {				
					var f = document.form1;   				  				
					f.action = "/index.screen";
	    			f.target = "_parent";             			
	    			f.submit();			
				}
				else {
					dlgErrorMsg(resultObj);
				}
				document.form1.isSubmit = false;
			}else if( resultObj.getRequestEvent() == "GET_EHR_DATA" ) {
				document.form1.isSubmit = false;
				if( resultObj.getSuccess() ) {
					alert("EHR데이타를 동기화 하였습니다.");
					jQuery("#btnSearch").click();
				}
				else {
					dlgErrorMsg(resultObj);
				}
			}
		}
		catch(errorObject) {
	        showErrorDlg("doResult()", errorObject);
		}
	}
	
	function searchAccDept(p_dept_cd, p_dept_nm){
		var win_id = "_searchDept";
		var link = "/lib/dlgSearchAccDept.screen";
		    link += "?pop_win_id="+win_id;
		fLayerPop(win_id, link, 600,400, '', '', 'NO');
		//flayerPopX(win_id, link, 600,400, '', '', 'NO');
	}
			 
	function searchAccDeptClose(result){
		 if( result == null ){
			document.form1.p_dept_cd.value = "";   //부서코드
			document.form1.p_dept_nm.value = "";   //부서명
		}else{
			document.form1.p_dept_cd.value = result[0];   //부서코드
			document.form1.p_dept_nm.value = result[1];   //부서명
		} 
		fLayerPopClose('_searchDept');
	}

	function doKeyPress() {
	    if( event.keyCode == 13 ) {
	    	jQuery("#btnSearch").click();
	    }
	}	
	
	function sheet1_OnSelectMenu(Text, Code) {
		switch(Text) {
			case "ExcelDown":
				jQuery("#btnExcel").click();
			break;
		}
	}
	
	function sheet1_OnSmartResize(Width, Height) { 
		sheet1.FitColWidth();
		autoResize();
		
	}

	function autoResize(){
		var t1_height = document.getElementById("search-table").scrollHeight + document.getElementById("title").scrollHeight + 24;
		var iframeHeight= document.body.scrollHeight - t1_height;   
		var iframeWidth= document.body.scrollWidth;   
		
		
		sheet1.SetSheetHeight(iframeHeight); 
	}	
	document.body.onresize = addEvent( document.body.onresize, "autoResize()");
</SCRIPT>


<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>

<form id="form1" name="form1" method="post" modular:type="search" style="width:100%;height:100%;">
<INPUT type="hidden" name="fevent" id="fevent" value="">
<INPUT type="hidden" name="p_user_pw" value="">
<INPUT type="hidden" name="p_buseo_nm" value="">
<INPUT type="hidden" name="p_job_dscr" value="">
<INPUT type="hidden" name="p_tel_no" value="">
<INPUT type="hidden" name="p_hand_tel_no" value="">
<INPUT type="hidden" name="p_e_mail" value="">
<INPUT type="hidden" name="acct_id" value="">

<INPUT type="hidden" name="j_usertype" value="head">
<input type='hidden' name='login_id' >
<input type='hidden' name='login_pw' >
<INPUT type="hidden" name="j_admin_login_gb" value="Y">

		  <!--  <div id='element_to_pop_up' style='display:none;'>
				<span class='button b-close' style='border-radius:7px 7px 7px 7px;box-shadow:none;font:bold 131% sans-serif;padding:0 6px 2px;position:absolute;right:-7px;top:-7px; background-color:#2b91af; color:#fff; cursor: pointer; display: inline-block; text-align: center;'><span>X</span></span> 닫기 버튼 (스타일은 알아서 지정)
				<div class='divcontent'></div> 컨텐츠가 들어갈 영역 지정 (이미지, html 등.. 여러가지를 동적으로 부를수 있다.
			</div> -->

   <div align="left" id="title">
    <ul>
     <li>사용자관리</li>
    </ul>
  </div> 
	<!-- 검색조건 시작 -->
	<table id="search-table" class="search-form-table">
		<colgroup>
			<col width="100" />
			<col width="350" />
			<col width="100" />
			<col width="150" />
			<col width="100" />
			<col width="*" />
			<col width="300" />
		</colgroup>
		<tr>
			<th>부서</th>
			<td>
		   		<%= InputText.get("p_dept_cd", params.get("p_dept_cd"), 12, 10, "ID,ReadOnly,PerSize") %>
		 		<%= InputText.get("p_dept_nm", params.get("p_dept_nm"), 32, 30, "ID,ReadOnly") %>
		  		<IMG onclick="searchAccDept(document.form1.p_dept_cd, document.form1.p_dept_nm)" src="/img/buyer/button/bt_search_right.gif" alt="부서찾기" border="0" align="absmiddle" style="cursor:hand;"> 				
			</td>
			<th>계정타입</th>
			<td>
				<%= HTMLMaker.getSelectTag(acctTypeRowSet, "ACCT_TYPE_ID", "ACCT_TYPE_NAME", "p_acct_type_id", "width:70%;height=18;", "<option value=''>--선택--</option>", params.get("p_acct_type_id")) %>
			</td>
			<th>사원번호</th>
			<td>
				<%= InputText.get("p_user_sabun", params.get("p_user_sabun"), 80, 50, "hangule, desc=사번, PerSize") %>
			</td>
			<td class="button" rowspan="2">
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSearch">검색</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnAdd">추가</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnSync">EHR Sync</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnClear">초기화</a></span>
				<span class="btnSearch center"><a href="javascript:void(0);" id="btnExcel">엑셀</a></span>
			</td>
		</tr>
		<tr>
			<th>현장</th>
			<td>
				<%=InputText.getSiteCodeNew("dept_cd2", "dept_nm2", "", user, params.get("dept_cd2"), params.get("dept_nm2"))%>
			</td>
			<th>이름</th>
			<td>
				<INPUT type="text" name="p_user_name" value="<%=params.get("p_user_name") %>" maxlength="50" class="input" style="IME-MODE : active;width:80%;"   desc='성명' onKeyPress="doKeyPress();">
			</td>
			<th>재직여부</th>
			<td>
				<SELECT name="p_status">
					<OPTION value="">전체</OPTION>
	                <OPTION value="Y">퇴직</OPTION>
	                <OPTION value="N" selected>재직</OPTION>
	            </SELECT>
			</td>
		</tr>
	</table>
	<!-- 검색조건 종료 -->
	<div id="sheet1_div" style="padding-top:5px; height: auto; min-height: 350px; overflow: auto;">
		<script>createIBSheet('sheet1','100%', '350px');</script>
	</div>
</FORM>