<?php
	require_once("config/connect.php");
	require_once("config/pageConfig.php");
	require_once("global_functions.php");
	check_login('', '', 'ENABLERKEY_ADMIN_COMBIARTIKEL');
?>
<!DOCTYPE HTML>
<html>
<head>
	<title>sITpos KOMBIARTIKEL ANLEGEN</title>
	<?php echo META_DATA_ADMIN; ?>
	<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.css">
	<style type="text/css">
		<?php include 'include/main.css'; ?>
		<?php include 'include/menue.css'; ?>
		
		#adminProdSearchResult { position:relative; width:95%; height:auto; max-height:40%; margin-left:2%; overflow-y:auto;}
		.searchResultLine {font-size:.95em; font-weight:bold; border-bottom:solid 1px #333; margin:6px 0; padding:0; line-height:1.4em; overflow:hidden; cursor:pointer;	}
		.getProductSearchField{ position:relative;  width:90%;  font-size:16px; font-weight:bold; line-height:1.3em; padding:2px 1%; border:1px solid #666;	}
		.getProductChildSearchField{ position:relative; float:left;  width:60%;  font-size:16px; font-weight:bold; line-height:1.3em; padding:2px 1%; border:1px solid #666;		}
		.getProductChildHeaderRight{	position:relative; float:left;  width:12%; font-size:16px; font-weight:bold; line-height:1.3em; margin:0 .5%; padding:2px 1%; text-align:left; 	}
		.getProductChildHeaderRight2{	position:relative; float:left;  width:12%; font-size:16px; font-weight:bold; line-height:1.3em; margin:0 .5%; padding:2px 1%; text-align:left; 	}
		#parentResultField {  position:relative; width:95%; height:auto; font-size:16px; padding:2px .5%; margin:1% 0; line-height:1.3em; font-weight:bold; 
					border-bottom:#555 solid 2px;	}
		.childSearchField {   position:relative; width:90%; border:gold solid 1px;			}
		#childResultField {  position:relative; width:98%;  font-size:16px; height:auto; max-height:80%; overflow-y:auto; margin:1% 0 0 1%;	}
		.childResultLine {  position:relative; float:left; width:65%; font-size:16px; font-style:italic; line-height:1.4em; 
			font-weight:bold;	margin:4px 0; border-bottom:1px solid #000; cursor:pointer;	}
		.childResultLineCheckbox {	 position:relative; float:right; width:33%;	 line-height:1.4em; 	} 
		.setCombiChildSplitRateCb {	position:relative; float:left; width:15%; margin:.25em 0; padding:0;	}
		.setCombiChildSplitRateField {position:relative; float:left; width:52%;font-size:.8em; line-height:1.2em;}
		.setCombiChildSplitRateBut {position:relative; float:right; width:30%; font-size:.8em; font-weight:bold; padding:.2em 0; border-radius:.3em; }
		
		#combiartikelListContainer {  width:95%; height:45%;  margin:2% 0 0 2%;  border-top:1px solid #000; 				}
		#combiartikelList{ position:relative; width:100%; height:88%; overflow-y:auto;	}
		.combiListHeader { font-size:.85em; font-weight:bold; text-align:center; margin:0; padding:3px 0 0 0; height:10%; border-bottom:2px solid #555; background:#555; color:#fff;	}
		.combiList { font-size:.95em; font-weight:bold; border-bottom:solid 1px #333; margin:6px 0; padding:0; line-height:1.4em; cursor:pointer;			}
	</style>
	<script>
		function getProductData(funcTarget, searchKey){
				
				if(funcTarget == 'searchToAddChild') currentParent = $("#currentParentId").val();
				else currentParent=0;
				
				$.ajax({
					type: "POST",
					url: "ajax_funktionen_kp.php",
					dataType : "html",
					data: {	functionKey:'searchProductData', functionTarget:funcTarget, searchkey:searchKey, currentParent:currentParent	},
					async: true,
					success:function(response){
						if(funcTarget == 'searchParent' )$("#adminProdSearchResult").html(response);
						else if(funcTarget == 'searchChild' )$("#childResultField").html(response);
						else if(funcTarget == 'searchToAddChild' )$("#adminProdSearchResult").html(response);
						else if(funcTarget == 'getCombiartikelTotal' )$("#combiartikelListContainer").html(response);	
						
					}
				});

		
		}
		
		function selectSearchResult(selectedId){
			toSelRes=$("#"+selectedId).html();
			console.log(toSelRes);
			$("#parentResultField").html(toSelRes);
			$("#adminProdSearchResult").html("");
			$("#currentParentId").val(selectedId);
			getProductData('searchChild', selectedId);
			$("#parentSearchField").val("");
			$(".adminContentColRight").css({ "visibility":"visible",			});
		}
		
		function addToParent(childId){
			currentParent=$("#currentParentId").val();
			if(currentParent > 0){
				$.ajax({
					type: "POST",
					url: "ajax_funktionen_kp.php",
					dataType : "html",
					data: {	functionKey:'addChildToParent', parrentId:currentParent, childId:childId	},
					async: true,
					success:function(response){
						getProductData('searchChild', currentParent);
					}
				});
			}
		}
		
		function deleteChild(childId){
			$.ajax({
					type: "POST",
					url: "ajax_funktionen_kp.php",
					dataType : "html",
					data: {	functionKey:'deleteChildFromCombiartikel', childId:childId	},
					async: true,
					success:function(response){
						currentParent=$("#currentParentId").val();
						getProductData('searchChild', currentParent);
					}
				});
		}
		
		function callChildDeleteDialog(childId){
			openDialog('', 'Teilartikel aus Kombiartikel löschen', '<p>Durch bestätigen löschen Sie diesen Artikel als Teilartikel des aufgerufenen Kombiartikels</p>', 'wrapper_admin', childId);
		}
		
		function openDialog(callFrom=false, boxTitle, dialogContent=false, wrappEr=false, paramId=false) {
			$("#combiartikelDialog").html("<div >"+dialogContent+"</div>");
			$("#combiartikelDialog").dialog({
			resizable: false,
			open: function(event, ui) { $(".ui-dialog-titlebar-close", ui.dialog | ui).hide(); 
										$("body").css({ "overflow":"hidden"		});

			},

			modal: true,
			title: boxTitle,
			height: 'auto',
			width: 600,
			position: { my: "center",  at: "center", of: "#"+wrappEr },
			dialogClass: "generalDialogBox",
				buttons: {
					"1": { id: 'dialogButL', text: 'Löschen bestätigen', click: function(){ 
							deleteChild(paramId);
							$(this).dialog("close"); }, "class":"button button_gross dialog_orange" },
					"2": { id: 'dialogButR', text: 'Fenster schließen', click: function(){ 
							$(this).dialog("close"); }, "class":"button button_gross dialog_orange" }	
				},

			
			});
		
		}
		
		function setCombiChildOptions(tTarget, elementId, childDbId){
			if(tTarget == 'printOption'){
				if($("#"+elementId).prop('checked')) setValue= 1;
				else setValue= 0;
			}
			else if(tTarget == 'pricesplitOption'){
				setValue = $("#"+elementId).val();

			}

			$.ajax({
					type: "POST",
					url: "ajax_funktionen_kp.php",
					dataType : "html",
					data: {	functionKey:'setChildFromCombiartikelOption', tTarget:tTarget, childDbId:childDbId, setValue:setValue	},
					async: true,
					success:function(response){
						console.log("Ajax response: " + response);
					}
				});
			
			
			
			
			
		
		}
	
	
	</script>
	
</head>
<body onload="getProductData('getCombiartikelTotal', false)" >
	<div id="wrapper_admin" class="wrapper_admin">
	<div id="combiartikelDialog"  ></div>
<?php
	menue_anzeigen();


?>
	<div id="adminContent">
		<div class="adminContentColLeft">
			<input type="hidden" id="currentParentId" />
			<input id="parentSearchField" class="getProductSearchField" type="text" placeholder="Kombiprodukt Suche" onkeyup="getProductData('searchParent', this.value)" />
			<div id="parentResultField" class="parentResultField" ></div>
			<div id="adminProdSearchResult" class="adminProdSearchResult" ></div>
			<div id="combiartikelListContainer"></div>
		</div>
		<div class="adminContentColRight">

				<input class="getProductChildSearchField" type="text"  placeholder="Teilprodukt Suche" onkeyup="getProductData('searchToAddChild', this.value)" />
				<div class='getProductChildHeaderRight' >Drucken</div><div class='getProductChildHeaderRight2' >% Satz</div><div class='cclear'></div>
				<div id="childResultField" class="childResultField" ></div>

		</div>
		<div class='cclear'></div>
		
		
		
		

	</div>


	</div>
</body>
</html>