SWAPLANGEDIT.jsp 34.7 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*,com.csc.library.session.*,com.csc.library.components.*,com.csc.library.report.*,java.util.*;"%>
<jsp:useBean id="SWAPLANGEDIT" class="com.csc.library.system.Task" scope="page" />
<jsp:useBean id="MultiSave" class="com.csc.library.dwr.Multisave" scope="page" />
<%
SWAPLANGEDIT.setChannel(request, response);
HelpEntry screen = (HelpEntry) SWAPLANGEDIT.process("HelpEntry","SWAPLANGSHOW");

CheckNull chk=new CheckNull();
ThaiUtilities thail = new ThaiUtilities();
String condition=thail.ASCII2Unicode(chk.chkNullString(request.getParameter("__fixCon")));
String numpage = chk.chkNullString(request.getParameter("__goPage"),"1");
String cmd = chk.chkNullString(request.getParameter("__cmd"),"");
String jsonHeader = chk.chkNullString(request.getParameter("__jsonHeader"),"");
String objJSON = chk.chkNullString(request.getParameter("__objJSON"),"");
String siteid = chk.chkNullString(request.getParameter("__siteid"),"");
String module_option = chk.chkNullString(request.getParameter("__moduleImport"),"");
String module_search = chk.chkNullString(request.getParameter("checkboxmodule"),"CENTER");
String searchthai = chk.chkNullString(request.getParameter("__searchthai"),"");
String searcheng = chk.chkNullString(request.getParameter("__searcheng"),"");
String searchcodeid = chk.chkNullString(request.getParameter("__searchcodeid"),"");

int nextrec = 1;
if(siteid != ""){
	DbInquiry di = new InitialInquiry(screen.getUProfile()).getDbInquiry("SWAPLANG_DETAIL");
	di.setColumn("LINE_NO");
	di.setFilter("SITEID = '"+siteid+"'");
	di.setOrderBy("LINE_NO DESC");
	di.refresh();
	di.first();
	while(di.next()){
		String line_no = di.getString("line_no");
		nextrec += Integer.parseInt(line_no);
		break;
	}
	di.closeConnection();
}

//--------------------- Set MultiSave Bean ---------------------------------
String tableName = "swaplang_detail";
String[] tableField = new String[]{"line_no$integer", "siteid", "codeid", "thai", "eng", "module"};
MultiSave.setUProfile(screen.getUProfile());
MultiSave.setNextRecord(nextrec);
MultiSave.setTable(tableName);
MultiSave.setField(tableField);
MultiSave.setJsonHeader(jsonHeader);

if (cmd.equalsIgnoreCase("save")) {
	System.out.println("*********************** save condition ***********************");
	MultiSave.setObjJson(objJSON);
	MultiSave.saveRecord();
	cmd = "savecomplete";
}

if (cmd.equalsIgnoreCase("delete")) {
	System.out.println("*********************** delete condition ***********************");
	MultiSave.setObjJson(objJSON);
	MultiSave.deleteRecord();
	cmd = "deletecomplete";
}

if (cmd.equalsIgnoreCase("addchild")) {
	System.out.println("*********************** addchild condition **********************");
	searchcodeid = "";
	objJSON = "{\"savejson\":[{\"line_no\":\""+nextrec+"\",\"siteid\":\""+siteid+"\",\"codeid\":\""+searchcodeid+"\",\"thai\":\""+searchthai+"\",\"eng\":\""+searcheng+"\",\"module\":\""+module_search+"\"}]}";
	MultiSave.setObjJson(objJSON);
	MultiSave.saveRecord();
	//condition = "siteid='"+siteid+"' and line_no="+String.valueOf(nextrec);
	condition = "siteid='"+siteid+"' and thai='' and eng=''";
}

if (cmd.equalsIgnoreCase("import")) {
	System.out.println("*********************** import condition ***********************");
	MultiSave.setModuleForImport(module_option);
	MultiSave.setSiteId(siteid);
	String[] field = new String[]{"thai", "eng"};
	MultiSave.setField(field);
	MultiSave.setJsonHeader("changelanguage");
	MultiSave.setObjJson(objJSON);
	MultiSave.ImportOldXmlToSave();
	cmd = "importcomplete";
}

ReportUDF udf = new ReportUDF();
String[] listModule = udf.getSystemCode("MODULETYPE_SWAPLANG",screen.getUProfile().get("lang"));

ListBox listboxStandard = new ListBox();
listboxStandard.setUProfile(screen.getUProfile());
listboxStandard.setName("Module_option"); //ชื่อ ListBox
listboxStandard.setValidCode("MODULETYPE_SWAPLANG"); //tag Systemcode ที่เรียกใช้
listboxStandard.setDisable("false");
listboxStandard.setChecked("01");

int maxLine = 50;
screen.setMaxLine(maxLine);
screen.getInquiry().setFilter(condition);
screen.getInquiry().setOrderBy("LINE_NO ASC");
screen.process();
%>
<html ng-app="myHR">
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css"/>
		<script  language="JavaScript" src="../JS/SCREEN.js"></script>
		<script type='text/javascript' src="../JS/ICONSMENU.js"></script>
		<script language='javascript' src="../JS/HOTKEY.js"></script>
		<script language='javascript'>setLang('<%=screen.getUProfile().get("lang")%>');</script>
		<script src="../JS/jquery-1.11.2.js" type="text/javascript"></script>
		<script src="../JS/jquery-ui-1.11.4.js" type="text/javascript"></script>
		<script type='text/javascript' src='/hr/dwr/interface/ChkDuplicateValue.js'></script>
		<script type='text/javascript' src='/hr/dwr/interface/export_xml.js'></script>
		<script type='text/javascript' src='/hr/dwr/engine.js'></script>
		<script type='text/javascript' src='/hr/dwr/util.js'></script>
		<script src="../JS/angular-1.3.15/angular.js"></script>
		<script type='text/JavaScript' SRC='../JS/ANGULAR/SCREEN_ANGULAR.js'></script>
		<link href="../CSS/jquery-ui-csc.css" rel="stylesheet" type="text/css"/>
		<style>
		input:focus { background-color: #99ccff; }
		.texterror { background-color: red; }
		.lineerror { background-color: red; }
		.portlet-import { cursor: pointer; }
		.portlet-export { cursor: pointer; }
		.portlet-delete { cursor: pointer; }
		.portlet-popup { position: absolute; display: block; }
		.swaplang_search_hide { display: none; }
		.swaplang_search_show { }
		.New_type { }
		.style1 {font-size: 12px}
		.bgwhite {background-color: white}
		</style>
		<script language="JavaScript" type="text/JavaScript">

		var strCMD = "<%=cmd%>";
		var lang = "<%=screen.getUProfile().get("lang")%>";
		switch (strCMD) {
			case "savecomplete":
			if(lang === 'tha'){
				alert('บันทึกเรียบร้อย');
			} else {
				alert('Save Data Successful');
			}
			break;
			case "importcomplete":
			if(lang === 'tha'){
				alert('นำเข้าข้อมูลเรียบร้อย');
			} else {
				alert('Import Data Successful');
			}
			break;
			case "deletecomplete":
			if(lang === 'tha'){
				alert('ลบเรียบร้อย');
			} else {
				alert('Delete Data Successful');
			}
			break;
		}

		//------------------- Global Variable -----------------------//
		var inputvalue;
		var jsObjJSON = {};
		var jsonArray = [];

		function alertSiteId(){
			if(lang === 'tha'){
				alert('กรุณาเลือกไซด์');
			} else {
				alert('Please Choose SiteID');
			}
		}

		function GoSearch(){
			with(document.cscform){
				var filterheal="";
				var modulecodition = setAndGetCheckedValueModule();
				filterheal=checkCondition(filterheal,__siteid,"siteid");
				filterheal=checkCondition(filterheal,__searchthai,"thai");
				filterheal=checkCondition(filterheal,__searcheng,"eng");
				filterheal=checkCondition(filterheal,__searchcodeid,"codeid");
				if(modulecodition != ""){
					filterheal=checkFilter(filterheal);
					filterheal+="module in("+modulecodition.substring(0,modulecodition.length-1)+")";
				}
				__fixCon.value=filterheal;
				console.log(__fixCon.value);
				search();
			}
		}

		function setAndGetCheckedValueModule(){
			var modulecodition = "";
			$('input[name="checkboxmodule"]:checked').each(function() {
				var getvalue = $(this).val();
				modulecodition += "'"+getvalue+"'";
				modulecodition += ","
			});
			$('input[name="__getcheckvalue"]').val(modulecodition);
			return modulecodition;
		}

		function checkFilter(fil){
			if(fil.length>0)
			fil+=" and ";
			return fil;
		}

		function checkCondition(filcon,objname,targetname){
			with(document.cscform){
				if(objname.value.length>0 && targetname === "siteid"){
					filcon=checkFilter(filcon);
					filcon+= targetname+"='"+objname.value+"'";
				} else if (objname.value.length>0){
					filcon=checkFilter(filcon);
					var find = '"';
					var repOriginalValue = new RegExp(find, 'g');
					var value = objname.value;
					value = value.replace(repOriginalValue,'\\\"');
					filcon+= "upper("+targetname+") like upper('%"+value+"%')";
				}
				return filcon;
			}
		}

		function GoDelete(){}
		function GoUpdate(){}
		function goHelp(helpName,inputName){
			with(document.cscform){
				var helpReturn;
				var fixcon=__fixCon.value;
				__fixCon.value="";
				if(inputName==="__siteid" ){ helpReturn="__siteid:siteid"; }
				linkHelp_Return(helpName,helpReturn);
				__fixCon.value=fixcon;
			}
		}

		function linkHelp(input){
			var param="PRU084.jsp?__helpName=MSITENAMEHELP&__helpReturn="+input+":siteid&__pageCall=SWAPLANGEDIT&__fixCon=&__checkVerify=off";
			win = window.open(param,"Help","left=150,top=150,width=600,height=400,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
			if(window.focus){win.focus();}
		}

		function GoClean(){
			with(document.cscform){
				decheckAll();
				__siteid.value="";
				__searchcodeid.value="";
				__searchthai.value="";
				__searcheng.value="";
				__cmd.value="";
			}
		}

		function checkEmpty(){
			with(document.cscform){
				if(__siteid.value === ""){
					__siteid.focus();
					return true;
				}
				return false;
			}
		}

		function goPage(page){
			with(document.cscform){
				__goPage.value=page;
				submit();
			}
		}

		function GoSave() {
			with(document.cscform){
				var obj = { savejson : jsonArray };
				$.extend(true, jsObjJSON, obj);
				console.log("jsObjJSON ==> "+JSON.stringify( jsObjJSON ));
				__objJSON.value = JSON.stringify( jsObjJSON );
				__cmd.value = "save";
				submit();
			}
		}

		function deleteChild() {
			with(document.cscform){
				var deleteArray = [];
				var i = 1;
				var obj = { savejson : deleteArray };
				$(".delcb").each(function(index,value){
					if($(this).is(':checked')){
						var value = $(this).val().split("$");
						deleteArray.push({"siteid":value[0],"line_no":value[1]});
						i++;
					}
				});
				$.extend(true, jsObjJSON, obj);
				console.log("jsObjJSON ==> "+JSON.stringify( jsObjJSON ));
				__objJSON.value = JSON.stringify( jsObjJSON );
				__cmd.value = "delete";
				submit();
			}
		}

		function addChild(){
			with(document.cscform){
				if(!checkEmpty()){
					setAndGetCheckedValueModule();
					__fixCon.value = "";
					__cmd.value = "addchild";
					submit();
				} else {
					alertSiteId();
				}
			}
		}

		function GoExport(){
			with(document.cscform){
				var chk = true;
				var getRadioLangValue = $('input[name="exportradio"]:checked').val();
				var getRadioConditionValue = $('input[name="conditionradio"]:checked').val();

				var getSiteID = "";
				if($('input[name="siteid_export"]').val() !== ""){
					getSiteID = $('input[name="siteid_export"]').val();
				} else {
					alertSiteId();
					chk = false;
				}

				var chkArray = [];
				var getTypeExport = $('input[name="type_exportradio"]:checked').val();
				if(getTypeExport === "OLD"){
					getRadioLangValue = "OLD";
				}
				$('input[name="module_export"]:checked').each(function() {
					var getCode = $(this).val();
					chkArray.push(getCode);
				});
				if(chkArray.length === 0){ //CheckModule
					if(lang === 'tha'){
						alert('กรุณาเลือก Module');
					} else {
						alert('Please Choose Module');
					}
					chk = false;
				}
				if(chk){
					console.log("getSiteID  ==> "+getSiteID+", getRadioLangValue  ==> "+getRadioLangValue+", getRadioConditionValue  ==> "+getRadioConditionValue+", chkArray  ==> "+chkArray+", getTypeExport  ==> "+getTypeExport);
					export_xml.export_zip(getSiteID, getRadioLangValue, getRadioConditionValue, chkArray, getTypeExport, callBackJ);
					$("#modal_export_file").dialog('close');
				}
			}
		}

		function callBackJ(data){
			var filename = data;
			var param="../FileDownload.jsp?uploadfield=export_xml.xmlmenu&filename="+filename;
			win = window.open(param,"Export File");
		}

		function swaptype(obj){
			with(document.cscform){
				var type_swap = document.getElementById("New_type");
				var data = obj.value;
				if( data == "NEW"){
					type_swap.style.display = "";
				} else {
					type_swap.style.display = "none";
				}
			}
		}

		function enterPress(event){
			if(event.keyCode === 13){
				document.getElementById('GoSearch').focus();
			}
		}

		$(document).ready(function(){
			var beforeinput = "";
			$(".inputcode").focus(function() {
				beforeinput = $(this).val();
			});
			$(".inputcode").change(function() {
				var this_attr_name = $(this).attr('name');
				var this_module = this_attr_name;
				this_module = this_module.replace("CODEID","MODULE");
				var this_siteid = this_attr_name;
				this_siteid = this_siteid.replace("CODEID","SITEID");

				var this_codeid_value = $(this).val();
				var this_module_value = $("select[name$='"+this_module+"']").val();
				var this_siteid_value = $("input[name$='"+this_siteid+"']").val();
				var chk = true;

				$(".inputcode").each(function(){
					var each_attr_name = $(this).attr('name');
					each_attr_name = each_attr_name.replace("CODEID","MODULE");
					var chkmodule = $("select[name$='"+each_attr_name+"']").val();
					each_attr_name = each_attr_name.replace("MODULE","SITEID");
					var chksiteid = $("input[name$='"+each_attr_name+"']").val();
					var chkcodeid = $(this).val();

					if($(this).attr('name') !== this_attr_name){
						if(this_siteid_value === chksiteid && this_codeid_value === chkcodeid && this_module_value === chkmodule){
							chk = false;
						}
					}
				});

				if(chk){
					chkDuplicateValue(this_siteid_value, this_codeid_value, this_module_value, this_attr_name, beforeinput);
				} else {
					var data = ["TRUE", this_attr_name, beforeinput];
					callBackBoolean(data);
				}
			});

			function chkDuplicateValue(siteid, codeid, module, inputname, beforeinput){
				ChkDuplicateValue.process(siteid, codeid, module, inputname, beforeinput, callBackBoolean);
			}

			function callBackBoolean(data){
				if(data[0] === "TRUE"){
					if(lang === 'tha'){
						alert('รหัสภาษาซ้ำ\nกรุณากรอกรหัสภาษาใหม่');
					} else {
						alert('CODEID Has Duplicate\nPlease Try Again');
					}
					$("input[name$='"+data[1]+"']").val(data[2]);
				} else {
					setObjValue(data[1]);
				}
			}
			$( ".swaplang_chkinput input" ).focus(function() {
				inputvalue = $(this).val();
				$(this).blur(function(){
					if($(this).val() != inputvalue){
						setObjValue($(this).attr('name'));
					}
				});
			});

			$( ".swaplang_chkinput select" ).change(function() {
				setObjValue($(this).attr('name'));
			});

			function setObjValue(dataname){
				var inputname = dataname.split("$");
				var siteid = inputname[1];
				var line_no = inputname[2];

				inputname = "__SITEID$"+siteid+"$"+line_no;
				var siteid = $("input[name$='"+inputname+"']").val();

				inputname = "__CODEID$"+siteid+"$"+line_no;
				var codeid = $("input[name$='"+inputname+"']").val();

				inputname = "__THAI$"+siteid+"$"+line_no;
				var thai = $("input[name$='"+inputname+"']").val();

				inputname = "__ENG$"+siteid+"$"+line_no;
				var eng = $("input[name$='"+inputname+"']").val();

				inputname = "__MODULE$"+siteid+"$"+line_no;
				var module = $("select[name$='"+inputname+"']").val();

				setObjArray(line_no, siteid, codeid, thai, eng, module);
				console.log("jsonArray ==> "+JSON.stringify( jsonArray ));
			}

			function setObjArray(line_no, siteid, codeid, thai, eng, module){
				var chk = true;
				for (var i=0; i<jsonArray.length; i++){
					if (jsonArray[i]["line_no"]) {
						var valueOldLineNo = jsonArray[i]["line_no"];
						var valueOldSiteId = jsonArray[i]["siteid"];
						if(valueOldLineNo === line_no && valueOldSiteId === siteid){
							jsonArray[i]["line_no"] = line_no;
							jsonArray[i]["siteid"] = siteid;
							jsonArray[i]["codeid"] = codeid;
							jsonArray[i]["thai"] = thai;
							jsonArray[i]["eng"] = eng;
							jsonArray[i]["module"] = module;
							chk = false;
						}
					}
				}

				if(chk){
					jsonArray.push({"line_no":line_no, "siteid":siteid, "codeid":codeid, "thai":thai, "eng":eng, "module":module});
				}
			}

			//----------------- Set Dialog UI import  -------------------
			$("#modal_import_file").dialog({
				autoOpen: false,
				minHeight: 100,
				width: 350,
				modal: true,
				closeOnEscape: true,
				draggable: false,
				resizable: false,
				buttons: {
					'Yes': function(){
						callback();
					},
					'No': function(){
						$(this).dialog('close');
					}
				}
			});
			$("#modal_export_file").dialog({
				autoOpen: false,
				minHeight: 200,
				width: 500,
				modal: true,
				closeOnEscape: true,
				draggable: true,
				resizable: true,
				buttons: {
					'Yes': function(){
						GoExport();
					},
					'No': function(){
						$(this).dialog('close');
					}
				}
			});
			$("#modal_confirm_delete").dialog({
				autoOpen: false,
				minHeight: 100,
				width: 350,
				modal: true,
				closeOnEscape: true,
				draggable: false,
				resizable: false,
				buttons: {
					'Yes': function(){
						deleteChild();
						$(this).dialog('close');
					},
					'No': function(){
						$(this).dialog('close');
					}
				}
			});

			//----------------- delete -------------------
			$(".portlet-delete").click( function() {
				$("#modal_confirm_delete").dialog( "option", "position", { my: "center top", at: "center top+200", of: window } ).dialog('open');
			});
			//----------------- export -------------------
			$(".portlet-export").click( function() {
				setModuleExport();
				$("input[name='siteid_export']").val($("input[name='__siteid']").val());
				$("#modal_export_file").dialog( "option", "position", { my: "center top", at: "center top+200", of: window } ).dialog('open');
			});

			//------ function Export -------
			function setModuleExport(){
				var mainModule = "";
				$(".module_main").each(function(){
					if($(this).prop('checked')){
						if(mainModule !== ""){
							mainModule += ",";
						}
						mainModule += $(this).val();
					}
				});

				var mainArray = mainModule.split(",");
				console.log("Main module ==> "+mainArray);
				$(".module_export").each(function(){
					if($.inArray( $(this).val(), mainArray ) !== -1){
						$(this).prop('checked',true);
						console.log("true");
					} else {
						$(this).prop('checked',false);
						console.log("false");
					}
				});
			}

			//----------------- import -------------------
			$(".portlet-import").click( function() {
				if(!checkEmpty()){
					$("#modal_import_file").dialog( "option", "position", { my: "center top", at: "center top+200", of: window } ).dialog('open');
				} else {
					alertSiteId();
				}
			});

			//------ function Import -------
			function callback(){
				var getPath =  $("input[name$='__FILEIMPORT']").val();
				if(getPath.indexOf(".xml") != -1 && getPath.indexOf("SWAPLANG") != -1){
					handleFileSelect();
					$("#modal_import_file").dialog( "close" );
				}else{
					alert("กรุณาเลือกไฟล์  swaplang.xml เท่านั้น");
				}
			}

			function handleFileSelect(){
				if (window.File || window.FileReader || window.FileList || window.Blob) {//(support IE 10+ ,Chrome, Firefox etc.) ps2. File API
					input = document.getElementById('__FILEIMPORT');
					var getPath =  $("input[name$='__FILEIMPORT']").val();
					var type = $("select[name$='__Module_option']").val();
					$('input[name="__dataimportType"]').val(type);

					if (!input) {
						alert("Um, couldn't find the fileinput element.");
					} else if (!input.files) {
						alert("This browser doesn't seem to support the `files` property of file inputs.");
					} else if (!input.files[0]) {
						alert("Please select a file before clicking 'Load'");
					} else {
						file = input.files[0];
						fr = new FileReader();
						fr.onload = function(e) {
							if(getPath.indexOf(".json") != -1 || getPath.indexOf(".txt") != -1){
								console.log(e.target.result);
							}else{
								sentXmlToServer(e.target.result);
							}
						};
						fr.readAsText(file, "UTF-8");
					}
				}else if(window.ActiveXObject) {//For Internet Explorer Ver 10 or Below
					var ForReading = 1, ForWriting = 2, ForAppending = 8;
					var xmlDoc = new ActiveXObject("Scripting.FileSystemObject"); //setting following to http://stackoverflow.com/questions/4153841/ || When Error
					var getPath = $("input[name$='__FILEIMPORT']").val();
					var canload = xmlDoc.OpenTextFile(getPath,ForReading);
					if (!canload.AtEndOfStream){
						sentXmlToServer(canload.ReadAll());
					}
				}
			}

			function sentXmlToServer(data){
				with(document.cscform){
					var jsonXmlArray = {"changelanguage":""};
					var xml = $.parseXML(data),
					$xml = $( xml );
					jsonXmlArray.changelanguage = setXMLtoJSONSwapLang($xml.find("changelanguage"));
					console.log("jsObjJSON ==> "+JSON.stringify( jsObjJSON ));
					__objJSON.value = JSON.stringify(jsonXmlArray);
					__moduleImport.value = $("select[name$='__Module_option']").val();
					__cmd.value = "import";
					submit();
				}
			}

			function setXMLtoJSONSwapLang(data){
				var find = '_';
				var repOriginalValue = new RegExp(find, 'g');
				var jsonArrayMenu = [];
				data.children().each(function(){
					var thaiValue = $(this).text();
					var engValue = $(this)[0].tagName;
					jsonArrayMenu.push(
						{
							"thai": thaiValue,
							"eng": engValue.replace(repOriginalValue," ")
						}
					);
				});
				return jsonArrayMenu;
			}
		});

		//-->
		</script>
	</head>
	<body>
		<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
		<script language="javascript">initToolTips();</script>
		<form name="cscform" method="post" action="SWAPLANGEDIT.jsp">

			<!----------BEGIN CSC INITIAL ZONE ------------------------>

			<%=screen.InitialVariable()%>

			<!----------END CSC INITIAL ZONE -------------------------->
			<input type="hidden" name="__cmd" value=""/>
			<input type="hidden" name="__help" value=""/>
			<input type="hidden" name="__notNull" value=""/>
			<input type="hidden" name="__helpReturn" value=""/>
			<input type="hidden" name="__helpName" value=""/>
			<input type="hidden" name="__pageCall" value=""/>
			<input type="hidden" name="__referPage" value=""/>
			<input type="hidden" name="__language" value="<%=screen.getUProfile().get("lang")%>"/>
			<input type="hidden" name="__lockPage" value=""/>
			<input type="hidden" name="__goPage" value=""/>
			<input type="hidden" name="__calendar"/>
			<input type="hidden" name="__screen" value="SWAPLANGEDIT"/>
			<input type="hidden" name="__webid"/>
			<input type="hidden" name="__readposter"/>
			<input type="hidden" name="__employeeid" value=""/>
			<input type="hidden" name="__docno" value=""/>
			<input type="hidden" name="__formulaid" value=""/>
			<input type="hidden" name="__fixCon" value="<%=condition%>"/>
			<input type="hidden" name="__orderBy" value="<%=request.getParameter("__orderBy")%>"/>
			<input type="hidden" name="__companyid"  value="<%=screen.getUProfile().get("companyid")%>"/>
			<input type="hidden" name="__complainid" value=""/>
			<input type="hidden" name="__getcheckvalue" value="<%=request.getParameter("__getcheckvalue")%>"/>
			<input type="hidden" name="__objJSON" value=""/>
			<input type="hidden" name="__moduleImport" value=""/>
			<input type="hidden" name="__jsonHeader" value="savejson"/>
			<script language="javascript">getInputFormatDate();</script>

			<%
			String[] getCheckValue = {"'start'"};
			String checkNull = request.getParameter("__getcheckvalue");
			if(checkNull!=null && !checkNull.isEmpty()){
				getCheckValue = checkNull.split(",");
			}
			%>

			<script language="JavaScript" src="../JS/HOTKEY.js"></script>
			<script language="javascript">
			var titlename=swap2String('Swap Language Edit');
			document.write(Icons("SWAPLANGEDIT,"+titlename));
			</script>

			<br/>
			<div align="center">
				<table cellpadding="0" cellspacing="0" class="largest">
					<tr>
						<td colspan="2" class="header" >SWAPLANGEDIT, <script language="javascript">swapLang(titlename);</script>&nbsp;</td>
					</tr>
					<tr>
						<td>
							<table class="maxsize" border="0" align="center" cellpadding="0" cellspacing="1">
								<tr>
									<td colspan="12" class="blankspace">
										<table width="638" border="0" align="center" cellpadding="0" cellspacing="1" class="inframe ">
											<tr>
												<td colspan="2" class="blankspace"></td>
											</tr>
											<tr>
												<td class="columnlabel"><%=screen.getLabel("siteid")%>&nbsp;</td>
												<td class="columnobject1"><%=screen.getInput("siteid")%></td>
											</tr>
											<tr>
												<td class="columnlabel"></td>
												<td class="columnobject1">---------------------------------Search---------------------------------</td>
											</tr>
											<tr>
												<td class="columnlabel">Module&nbsp;</td>
												<td class="columnobject1">
													<table width="200" border="0" align="left" cellpadding="0" cellspacing="1">
														<%
														int count = 0;
														for(int i = 0;i<listModule.length;i++){
															if(i%4==0){
																%>
																<tr>
																	<%
																}
																boolean createCheckedBox = false;
																for(int j =0;j<getCheckValue.length;j++){//Check CheckBox when CheckBox is checked
																	String foo = getCheckValue[j];
																	if(foo.indexOf("'") != -1){ //Check Null Value
																		if(getCheckValue[j].split("'")[1].equals(listModule[i].split(",")[0])){
																			createCheckedBox = true;
																		}
																	}
																}
																if(createCheckedBox){
																	%>
																	<td class="columnobject1">
																		<input type="checkbox" value=<%=listModule[i].split(",")[0]%> name="checkboxmodule" class="module_main" checked/>&nbsp;<%=listModule[i].split(",")[1]%>
																	</td>
																	<%
																} else {
																	%>
																	<td class="columnobject1">
																		<input type="checkbox" value=<%=listModule[i].split(",")[0]%> name="checkboxmodule" class="module_main"/>&nbsp;<%=listModule[i].split(",")[1]%>
																	</td>
																	<%
																}
																count = count + 1;
																if(count>0&&count%4==0){
																	%>
																</tr>
																<%
																count = 0;
															}
														}
														%>
													</table>
												</td>
											</tr>
											<tr>
												<td class="columnlabel">&nbsp;</td>
												<td class="columnobject1">
													<a href="javascript:;" onClick="checkAll()"><img src="../IMAGES/BUTTON/SELECTALL.gif" border="0"></a>
													<a href="javascript:;" onClick="decheckAll()"><img src="../IMAGES/BUTTON/DESELECTALL.gif" border="0"></a>
												</td>
											</tr>
											<tr>
												<td class="columnlabel"><%=screen.getLabel("CODEID")%>&nbsp;</td>
												<td class="columnobject1"><input type="Text" name="__searchcodeid" size="50" value="<%=searchcodeid%>" onkeydown="enterPress(event)"></td>
											</tr>
											<tr>
												<td class="columnlabel"><%=screen.getLabel("THAI")%>&nbsp;</td>
												<td class="columnobject1"><input type="Text" name="__searchthai" size="50" value="<%=searchthai%>" onkeydown="enterPress(event)"></td>
											</tr>
											<tr>
												<td class="columnlabel"><%=screen.getLabel("ENG")%>&nbsp;</td>
												<td class="columnobject1"><input type="Text" name="__searcheng" size="50" value="<%=searcheng%>" onkeydown="enterPress(event)"></td>
											</tr>
											<tr>
												<td class="columnlabel">&nbsp;</td>
												<td>
													<a href="javascript:GoSearch();" id="GoSearch"><img src="../IMAGES/BUTTON/SEARCH.gif" border="0"></a>
													<span class="portlet-export"><img src="../IMAGES/BUTTON/EXPORT.gif"  border="0"></span>
												</td>
											</tr>
											<tr>
												<td colspan="2" class="columnlabel"></td>
											</tr>
										</table>
										<br/>
										<div align="right" class="style1"><%=screen.getPageTag()%></div>
										<table width="638" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#808080" class="inframe" id="resultData">
											<tr class="title1">
												<td width="2%" class="row3" align="center"><swaplang code="SW000289"></swaplang></td>
												<td width="4%" nowrap class="row3" align="center"><swaplang code="SW001393"></swaplang></td>
												<td width="5%" nowrap class="row3" align="center"><%=screen.getLabel("swaplang_detail","siteid")%></td>
												<td width="15%" nowrap class="row3" align="center"><%=screen.getLabel("swaplang_detail","codeid")%></td>
												<td width="25%" nowrap class="row3" align="center"><%=screen.getLabel("swaplang_detail","thai")%></td>
												<td width="25%" nowrap class="row3" align="center"><%=screen.getLabel("swaplang_detail","eng")%></td>
												<td width="23%" nowrap class="row3" align="center"><%=screen.getLabel("swaplang_detail","module")%></td>
											</tr>
											<%
											if (numpage.indexOf("+") >= 0 || numpage.indexOf("-") >= 0){
												numpage = numpage.substring(1, numpage.length());
											}

											int i = (maxLine * Integer.parseInt(numpage)) - (maxLine - 1);
											while (screen.nextRec()) {
												if(screen.checkLinePage()){
													int line_no = Integer.parseInt(screen.getString("swaplang_detail","line_no"));
													String row_siteid = screen.getString("swaplang_detail","siteid");
													ListBox listbox1 = new ListBox();
													listbox1.setUProfile(screen.getUProfile());
													listbox1.setName("MODULE$"+row_siteid+"$"+line_no); //ชื่อ ListBox
													listbox1.setValidCode("MODULETYPE_SWAPLANG"); //tag Systemcode ที่เรียกใช้
													listbox1.setDisable("false");
													listbox1.setChecked(screen.getString("swaplang_detail","module"));
													%>
													<tr align="center">
														<td><input class="delcb" type="checkbox" name="__DEL$<%=row_siteid%>$<%=line_no%>" value="<%=row_siteid%>$<%=line_no%>"></td>
														<td><%=i%></td>
														<td><%=row_siteid%><input type="hidden" name="__SITEID$<%=row_siteid%>$<%=line_no%>" value="<%=row_siteid%>"></td>
														<td><input type="Text" name="__CODEID$<%=row_siteid%>$<%=line_no%>" size="12" value="<%=screen.getString("swaplang_detail","codeid")%>" class="inputcode"></td>
														<td class="swaplang_chkinput"><input type="Text" name="__THAI$<%=row_siteid%>$<%=line_no%>" size="30" value="<%=screen.getString("swaplang_detail","thai")%>"></td>
														<td class="swaplang_chkinput"><input type="Text" name="__ENG$<%=row_siteid%>$<%=line_no%>" size="30" value="<%=screen.getString("swaplang_detail","eng")%>"></td>
														<td class="swaplang_chkinput"><%=listbox1.process()%></td>
													</tr>
													<%
												}
												if(screen.outLinePage()){ break; }
												i++;
											}
											%>
										</table>
									</td>
								</tr>
								<tr>
									<td colspan="2" class="blankspace"></td>
								</tr>
								<tr>
									<td colspan="2" align="center">
										<a href="javascript:;" onClick="addChild()"><img src="../IMAGES/BUTTON/ADD.gif"  border="0"></a>&nbsp;&nbsp;
										<span class="portlet-import"><img src="../IMAGES/BUTTON/BROWSE.gif" border="0"></span>&nbsp;&nbsp;
										<span class="portlet-delete"><img src="../IMAGES/BUTTON/DELETE.gif" border="0"></span>
									</td>
								</tr>
								<tr>
									<td colspan="2" class="blankspace"></td>
								</tr>
								<tr>
									<td colspan="2" class="bottom"></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</div>

			<!---------- POPUP Jquery UI ------------------------>
			<div id="modal_import_file" class="portlet-popup" title="Import File">
				<div id="dialog_tips" align="center">
					<swaplang code="SW011600"></swaplang> :: SWAPLANG.xml
				</div>
				<br/>
				<div id="dialog_tips" align="left">
					Module:&nbsp;&nbsp;<%=listboxStandard.process()%>
				</div>
				<br/>
				<input name="__FILEIMPORT" id="__FILEIMPORT" type="file" size="30" accept="text/xml,text/json,text/txt"/>
			</div>

			<div id="modal_confirm_delete" class="portlet-popup" title="Confirm Delete?">
				<span>
					<swaplang code="SW011601"></swaplang>
				</span>
			</div>

			<div id="modal_export_file" class="portlet-popup" title="Export File">
				<table border="1" class="inframe bgwhite">
					<tr>
						<td width="150">&nbsp;&nbsp;<%=screen.getLabel("siteid")%>&nbsp;</td>
						<td>&nbsp;&nbsp;
							<input name="siteid_export" size="10" readonly="true" alt="SITEID" onmousemver="toolTip('SITEID')" type="Text"/>
							<a href="javascript:linkHelp('siteid_export');" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('siteid_export_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)">
								<img src="http://localhost:8082/hr/IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="SEARCH" name="siteid_export_image" align="absmiddle" border="0" height="20" width="20"/>
							</a>
						</td>
					</tr>
					<tr>
						<td width="80">&nbsp;&nbsp;Module&nbsp;</td>
						<td width="350">
							<table border="0" align="left" cellpadding="0" cellspacing="1" class="inner2">
								<%
								count = 0;
								for(i = 0;i<listModule.length;i++){
									if(i%2==0){
										%><tr><%
									}
									%>
									<td class="columnobject1">&nbsp;&nbsp;<input type="checkbox" value=<%=listModule[i].split(",")[0]%> name="module_export" class="module_export"/>&nbsp;<%=listModule[i].split(",")[1]%>&nbsp;&nbsp;</td>
									<%
									count = count + 1;
									if(count>0&&count%4==0){
										%></tr><%
										count = 0;
									}
								}
								%>
							</table>
						</td>
					</tr>
					<tr>
						<td width="150">&nbsp;&nbsp;Condition Value&nbsp;</td>
						<td>&nbsp;&nbsp;
							<input type="radio" name="conditionradio" value="MODULE" checked>&nbsp;Module</input>&nbsp;
							<input type="radio" name="conditionradio" value="CENTER">&nbsp;Center</input>&nbsp;
						</td>
					</tr>
					<tr>
						<td>&nbsp;&nbsp;Type Export&nbsp;</td>
						<td>&nbsp;&nbsp;
							<input onclick="swaptype(this);" type="radio" name="type_exportradio" value="OLD" checked>&nbsp;OLD</input>&nbsp;
							<input onclick="swaptype(this);" type="radio" name="type_exportradio" value="NEW" >&nbsp;NEW</input>&nbsp;
						</td>
					</tr>
					<tr style="display: none;" id="New_type">
						<td>&nbsp;&nbsp;Language Export&nbsp;</td>
						<td>&nbsp;&nbsp;
							<input type="radio" name="exportradio" value="ALL" checked>&nbsp;All</input>&nbsp;
							<input type="radio" name="exportradio" value="THAI">&nbsp;Thai</input>&nbsp;
							<input type="radio" name="exportradio" value="ENG">&nbsp;Eng</input>&nbsp;
						</td>
					</tr>
				</table>
			</div>
		</form>
	</body>
</html>