<!DOCTYPE HTML>
<%@page contentType="text/html; charset=UTF-8"%>
<%@ page import="com.csc.library.entry.*" %>
<%@ page import="com.csc.library.system.*" %>
<%@ page import="com.csc.library.session.*" %>
<%@ page import="com.csc.library.utilities.*" %>
<%@ page import="com.csc.library.database.*" %>
<%@ page import="com.csc.library.report.ReportUDF" %>

<%@ include file="../CHECKPROFILE.jsp" %>

<jsp:useBean id="uset" class="com.csc.library.system.Task" scope="page"/>
<jsp:setProperty name="uset" property="appname" value="empview" /> 
<%
	uset.setChannel(request,response);


	HelpEntry screen_udetail=(HelpEntry)uset.process("HelpEntry","MUSERHELP");

	SingleEntry screen=(SingleEntry)uset.process("SingleEntry","PI-PASSWORD");
	CheckNull chk=new CheckNull();
	String filter="";
	filter=" lower(usernameid) like lower('"+uprofile.get("username")+"')";
	screen_udetail.getInquiry().setFilter(filter);
	screen_udetail.getInquiry().refresh();
	
	screen.getRecord();

	ReportUDF muserstate=new ReportUDF();

	screen_udetail.nextRec();

	String pwdflag=muserstate.getSystemCode("PWDSTATUS",uset.getUProfile().get("lang"),screen_udetail.getString("pwdstatus"));
	String cmd=chk.chkNullString(request.getParameter("__cmd"));
	String password = "";
	screen.referLangOff();
	
	if(request.getParameter("__password")!=null && screen.getRecord().getConfirmStatus()==-99) {		
		password=chk.chkNullString(request.getParameter("__password"));
	}
	screen_udetail.referLangOn();


	if(cmd.equals("")||screen.getRecord().getConfirmStatus()<0||screen.getRecord().getConfirmStatus()==2){
	 	screen.getRecord().set("usernameid",screen.getUProfile().get("user"));
		screen.getRecord().set("company",screen.getUProfile().getCompanyid());
		screen.getRecord().search();	
	 }

	String fieldtype=screen.getRecord().getField("password").getType().toLowerCase();
%>

<html ng-app="myHR">
	<head>
		<script type="text/javascript" src="../JS/webtoolkit.sha1.js"></script>
		<script language="JavaScript" src="../JS/SCREEN.js"></script>
		<script type='text/javascript' src='../JS/ICONSMENU.js'></script>
	</head>
	<body>
		<div class="bg-com"></div>
		<jsp:include page="EMV_HEADMENU.jsp" flush="true" />

		<script type="text/javascript">
			setLang("<%=screen.getUProfile().get("lang")%>");
			var swap = new swaplang();
            var titlename = swap.swap2String("SW012326");
			setPageTitle(titlename);

			setLang("<%=screen_udetail.getUProfile().get("lang")%>"); 

			EngCode[200]="password is used "
			ThaiCode[200]="รหัสผ่านนี้ถูกใช้ไปแล้ว";

			EngCode[201]="Not enough number or charactor "
			ThaiCode[201]="รหัสผ่านมีตัวเลขหรือตัวอักษรน้อยกว่าที่กำหนด";

			EngCode[202]="password invalid "
			ThaiCode[202]="รหัสผ่านไม่ถูกต้อง";

			EngCode[203]="Password should have least <%=screen.getDataLabel("muser_role","pwmin")%> characters.\n"
			ThaiCode[203]="รหัสผ่านควรมีความยาวอย่างน้อย <%=screen.getDataLabel("muser_role","pwmin")%> ตัวอักษร\n";
			
			EngCode[204]="Characters [a-zA-Z] least <%=screen.getDataLabel("muser_role","pwstr")%>\n"
			ThaiCode[204]="ตัวอักษร [a-zA-Z] อย่างน้อย <%=screen.getDataLabel("muser_role","pwstr")%>\n";

			EngCode[205]="Number [0-9] least <%=screen.getDataLabel("muser_role","pwnumber")%>\n"
			ThaiCode[205]="ตัวเลข  [0-9] อย่างน้อย <%=screen.getDataLabel("muser_role","pwnumber")%>\n";

			EngCode[206]="Special characters [@#+$%] least  <%=screen.getDataLabel("muser_role","pwspecial")%>\n"
			ThaiCode[206]="อักขระพิเศษ  [@#+$%] อย่างน้อย  <%=screen.getDataLabel("muser_role","pwspecial")%>\n";

			function checkConfirm(){
				var conCode="";
				var conDesc="";
				with(document.cscform){
				//	alert(__confirm.value);
				 conCode=getConfirmIndex(__confirm.value,"0");
				 conDesc=getConfirmIndex(__confirm.value,"1");
				 if(__confirm.value=="-6")alert(MyCode[200]);
				 if(__confirm.value=="-11")alert(MyCode[202]);
				 if(__confirm.value=="-7"||__confirm.value=="-8"||__confirm.value=="-9"||__confirm.value=="-10")alert(MyCode[201]);
				 if(__confirm.value=="4")alert(MyCode[19]);
				 if(__confirm.value=="1" || __confirm.value=="2")alert(MyCode[18]);
				 if(__confirm.value=="-1" || __confirm.value=="-2" || __confirm.value=="-6")alert(MyCode[17]);
					if(conCode=="-99"){
						updateRecord();
					}
				}
			}

			$(document).ready(function(){
				var lang='<%=screen_udetail.getString("lang")%>';
				
				var numcount=$("div.child-tab").length;
				var tabheight=$(".tab-body").height();
				var result=Math.ceil(tabheight/numcount)+1;
				$(".child-tab").css("height",result);
				$(".child-tab").css("line-height",result+"px");
				
				/*if (lang=="ENG"){
					$("input[name=__lang]:nth-of-type(1)").attr("checked",true);
				} else if(lang=="THA"){
					$("input[name=__lang]:nth-of-type(0)").attr("checked",true);
				}*/

				$(".child-tab").click(function(){
					if ($(this).data("tab"))
					{
						$(".tab-body").removeClass("active");
						$(".child-tab").removeClass("active");

						var tabid=$(this).data("tab");

						$(this).addClass("active");
						$(tabid).addClass("active");
					}
				});

				$.chkPassword = function(){
					if (($("input[name=__password]").val()=="") && ($("input[name=__newpassword]").val()=="") && ($("input[name=__confirmpw]").val()=="")){
						$("input[name=__password]").prop("disabled",true);										
						$("input[name=__newpassword]").prop("disabled",true);
						$("input[name=__confirmpw]").prop("disabled",true);
						return true;

					}else if ( $("input[name=__password]").val()=="" ){
						alert(MyCode[0]);
						$("input[name=__password]").focus();
						return false;

					} else if ( $("input[name=__newpassword").val()=="" ){
						alert(MyCode[0]);
						$("input[name=__newpassword]").focus();
						return false;
					} else if ( $("input[name=__confirmpw]").val()=="" ){
						alert(MyCode[0]);
						$("input[name=__confirmpw]").focus();
						return false;

					} else if ($("input[name=__newpassword]").val().length<<%=screen.getDataLabel("muser_role","pwmin")%>){
						alert(MyCode[203]);
						$("input[name=__newpassword]").focus();
						return false;
					} else if ($("input[name=__newpassword").val()!=$("input[name=__confirmpw").val()){
						alert(MyCode[50]);
						$("input[name=__newpassword]").val("");
						$("input[name=__confirmpw]").val("");
						return false;

					}else {
						return true;
					}
				};

				$.GoSave = function (){
					if ($.chkPassword()){

						if ( !$("input[name=__password]").prop("disabled") && !$("input[name=__newpassword").prop("disabled") && !$("input[name=__confirmpw").prop("disabled") ){
							var msg="";
							var niw=$("input[name=__newpassword]").val().replace(/[\D\.]+/g,"").length;
							var ciw=$("input[name=__newpassword]").val().replace(/[^a-zA-Z]+/g,"").length;
							var siw=$("input[name=__newpassword]").val().length-(niw+ciw);
							
							$("input[name=__niw]").val(niw);
							$("input[name=__ciw]").val(ciw);
							$("input[name=__siw]").val(siw);
							if (niw<<%=screen.getDataLabel("muser_role","pwnumber")%>){
								msg+=MyCode[205];
							}
							
							if(ciw<<%=screen.getDataLabel("muser_role","pwstr")%>){
								msg+=MyCode[204];
							}
							
							if(siw<<%=screen.getDataLabel("muser_role","pwspecial")%>){
								msg+=MyCode[206];
							}

							if(msg.length>0){
								msg=MyCode[201]+"\n"+msg;
								alert(msg);
							}else{
							<% 
								if (fieldtype.equals("password")){
							%>
									$("input[name=__password]").val(SHA1($("input[name=__password]").val()));
									$("input[name=__newpassword]").val(SHA1($("input[name=__newpassword]").val()));
									$("input[name=__confirmpw]").val(SHA1($("input[name=__confirmpw]").val()));
									update();
							<%
								}
							%>
							}
						}else {
							update();
						}
					}
				};
			});
		</script>

		<section>
			<div class="container csc-content">
				<div class="row">
					<div class="tab">
						<div class="tab-left">
							<div class="child-tab active" data-tab="#1" swlang code='SW012326'>
								User Detail
							</div>
							<div class="child-tab" data-tab="#2" swlang code='SW012327'>
								Profile Setting
							</div>
						</div> <!-- end tab-left -->
						<div class="tab-body active" id="1">
							<div class="center">
								<h2 swlang code='SW012326'>User Detail</h2>
							</div>
					
							<div class="tab-detail">
								<div class="tab-data tab-form">
									<div class="col-sm-3">
										<span swlang code='SW001984'>Name-Lastname</span>
									</div> 

									<div class="col-sm-1">
										:
									</div>

									<div class="col-sm-6">
										<%=screen_udetail.getString("MEMPLOYEE","fullname")%>
									</div>
												
								</div>
							</div><!-- end tab detail-->
									
							<div class="tab-detail">
								<div class="tab-data tab-form">
									<div class="col-sm-3">
										<span swlang code='SW012328'>User Group</span>
									</div>

									<div class="col-sm-1">
										:
									</div>

									<div class="col-sm-6">
										<%=screen_udetail.getString("USER_LEVEL")%>
									</div>
								</div>
							</div>
							<div class="tab-detail">
								<div class="tab-data tab-form">
									<div class="col-sm-3">
										<span swlang code='SW012329'>User Role</span>
									</div>

									<div class="col-sm-1">
										:
									</div>

									<div class="col-sm-6">
										<%=screen_udetail.getString("USER_ROLE")%>
									</div>
								</div>
							</div> <!-- end tab-detail -->

							<div class="tab-detail">
								<div class="tab-data tab-form">
									<div class="col-sm-3">
										<span swlang code='SW012330'>Password Expire date</span>
									</div>

									<div class="col-sm-1">
										:
									</div>
											
									<div class="col-sm-6">
										 <%=screen_udetail.getString("expiredate")%>
									</div>
								</div>
							</div> <!-- end tab-detail-->

							<div class="tab-detail">
								<div class="tab-data">
									<div class="col-sm-3">
										<span swlang code='SW012331'>Password Status</span>
									</div>

									<div class="col-sm-1">
										:
									</div>
									<div class="col-sm-6">
										<%=pwdflag%>
									</div>
								</div>
							</div> <!-- end tab-detail -->
			
							
						</div><!-- end tab 1-->
						
						<div class="tab-body" id="2">
							<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
							<form name="cscform" method="post">
								<!----------BEGIN CSC INITIAL ZONE ------------------------>

								<%=screen.InitialVariable()%>

								<!----------END CSC INITIAL ZONE -------------------------->
								<input type="hidden" name="__cmd" value=""> 
								<input type="hidden" name="__screen" value="EMV_USERSETTING">
								<input type="hidden" name="__help" value="">
								<input type="hidden" name="__fixCon" value="">
								<input type="hidden" name="__helpReturn" value="">
								<input type="hidden" name="__notNull" value="<%=screen.getRequire()%>">
								<input type="hidden" name="__company" value="<%=screen.getUProfile().get("companyid")%>"> 
								<input type="hidden" name="__usernameid" value="<%=screen_udetail.getString("usernameid")%>">
								<input type="hidden" name="__user_role" value ="<%=screen_udetail.getDataLabel("user_role")%>">
								<input type="hidden" name="__referPage" value="">
								<input type="hidden" name="__isclean" value ="1">
								<input type="hidden" name="__niw" value ="0">
								<input type="hidden" name="__ciw" value ="0">
								<input type="hidden" name="__siw" value ="0">
							
								<script type="text/javascript">//initToolTips();</script>
								<div class="center">
									<h2 swlang code='SW012327'>Profile setting</h2>
								</div>
								<div class="tab-detail">
									<div class="tab-data tab-form">
										<div class="col-sm-3">
											<div class="control-label control-label-form" swlang code='SW001807'>Old Password</div>
										</div>

										<div class="col-sm-1">:
										</div>
										
										<div class="col-sm-6">
											<input type="password" class="form-control" name="__password">
										</div>
									</div><!-- end tab-data -->
								</div><!-- end tab-detail -->

								<div class="tab-detail">
									<div class="tab-data tab-form">
										<div class="col-sm-3">
											<div class="control-label control-label-form" swlang code='SW001808'>New Password</div>
										</div>
										
										<div class="col-sm-1">:
										</div>

										<div class="col-sm-6">
											<input type="password" class="form-control" name="__newpassword">
										</div>
									</div><!-- end tab-data -->
								</div><!-- end tab-detail -->

								<div class="tab-detail">
									<div class="tab-data tab-form">
										<div class="col-sm-3">
											<div class="control-label control-label-form" swlang code='SW001809'>Confirm Password</div>
										</div>
										
										<div class="col-sm-1">:
										</div>

										<div class="col-sm-6">
											<input type="password" class="form-control" name="__confirmpw">
										</div>
									</div><!-- end tab-data -->
								</div><!-- end tab-detail-->

								<div class="tab-detail">
									<div class="tab-data tab-form">
										<div class="col-sm-3">
											<div class="control-label control-label-form" swlang code='SW012332'>Set Default Language</div>
										</div>

										<div class="col-xs-1">:
										</div>

										<div class="col-sm-6">	
											<%=screen.getInput("lang")%>
											<!--<label class="radio-inline">
												<input type="radio" name="__lang" id="__langth" value="THA"> Thai
											</label>
											<label class="radio-inline">
												<input type="radio" name="__lang" id="__langen" value="ENG"> English
											</label>-->
											
										</div>
									</div><!-- end tab-data -->
								</div><!-- end tab-detail-->

								<div class="tab-detail center">
									<a href="javascript:$.GoSave()" class="btn btn-primary" id="usersub" swlang code='SW012098'>Submit</a>
									<!-- <a href="#" class="btn btn-primary" id="usercan" swlang code='SW012132'>Cancel</a> -->
								</div> <!-- end button-->

								<div class="tab-note">
									 <%@ include file="../msgpassword.jsp" %>
								</div>
								<%=screen.endJSP()%>
							</form>
						</div><!-- end tab2 -->
						
					</div> <!-- end tab -->
				</div>
			</div>
		</section>
		<jsp:include page="FOOTER.jsp" flush="true" />
	</body>
</html>