<?php
header('Content-Type: text/html; charset=utf-8');
error_reporting(0);
$path="../../";
include("../../map.php");
include("../../scripts.php");
include("../../secure.php");

if (isset($_GET["optionGrupID"]) && $_GET["optionGrupID"] > 0) {
    $optionGrupID = intval($_GET["optionGrupID"]); // Güvenlik için int'e çevir
	$sql=mysqli_query($conn, "select * from genel where id='".$optionGrupID."'"); $rs=mysqli_fetch_assoc($sql);
    $qry = "ne='option' AND s1='$optionGrupID' AND "; $text=$rs["n1"]." Seçenek"; $ne='option';
} else {
    $qry = "ne='optionGrup' AND "; $text="Seçenek Grubu"; $ne='optionGrup';
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title><?php echo $vyonlar?></title>
</head>
<body>
	<div class="qmodal">
		<div class="qmodal-content">
			<!-- Header with Action Buttons -->
			<div class="qmodal-header">
					<button type="button" class="btn btn-info" onclick="location.href='?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>'"><i class="fas fa-home"></i></button>
				<?php if($MSA==1){?>
					<button type="button" class="btn btn-danger" onclick="location.href='?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=clear_optionGrup'"><i class="fas fa-trash"></i></button>
				<?php }?>
			</div>
			<!-- Left Tab Menu -->
			<div class="v8-columns">
				<!-- Content Area -->
				<div ts1="<?php echo dtarih($rs["ts1"],"gg ka yy time");?>" ts2="<?php echo dtarih($rs["ts2"],"gg ka yy time");?>" ts3="<?php echo dtarih($rs["ts3"],"gg ka yy time");?>">
					<form method="POST" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=add_optionGrup&optionGrupID=<?php echo intval($_GET["optionGrupID"]); ?>" autocomplete="off" name="f0">
						<table class="table" style="min-width: 800px;">
							<tr class="addtr">
								<td class="">
									<input type="text" name="n1" class="form-control" placeholder="Yeni <?php echo $text?>">
								</td>
							<?php if (!isset($_GET["optionGrupID"]) || $_GET["optionGrupID"] <= 0) { ?>
								<td class="w6">
									<input type="checkbox" name="s2" value="1" class="xl">
								</td>
							<?php }?>
								<td class="w5">
									<input type="text" class="form-control" name="s12" value="0">
								</td>
								<td class="w8">
									<div class="input-group-btn">
										<button tabindex="-1" class="btn btn-warning mbtn" type="submit"><i class="fa fa-plus"></i></button>
									</div>
								</td>
							<tr>
							</form>

							<?php $sql=mysqli_query($conn, "select * from genel where $qry n1 LIKE '%".$_POST["q"]."%' order by n1 asc"); while($rs=mysqli_fetch_assoc($sql)){?>
							<form  method="POST" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=update_optionGrup&optionGrupID=<?php echo $_GET["optionGrupID"];?>&id=<?php echo $rs["id"];?>" name="f<?php echo $rs["id"]?>">
								<input type="hidden" name="KID[]" value="<?php echo $rs["id"]?>" />
								<input type="hidden" name="optionGrupID" value="<?php echo $rs["id"]; ?>">
								<tr data-id="<?php echo $rs["id"];?>">
									<td><input type="text" name="n1" class="form-control" value="<?php echo $rs["n1"];?>" placeholder="<?php echo $text?>"></td>
								<?php if (!isset($_GET["optionGrupID"]) || $_GET["optionGrupID"] <= 0) { ?>
									<td class="w6">
										<input type="checkbox" name="s2" value="1" class="xl" <?php echo ($rs["s2"] == 1) ? 'checked' : ''; ?>>
									</td>
								<?php }?>
								<td class="w5">
									<input type="text" class="form-control" name="s12" value="<?php echo !empty($rs["s12"]) ? $rs["s12"] : 0; ?>">
								</td>
									<td class="w8">
										<div class="input-group-btn">
										<?php if (!$_GET["optionGrupID"] > 0) {?>
											<button tabindex="-1" class="btn btn-warning" type="button" onclick="location.href='?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&optionGrupID=<?php echo $rs["id"];?>'"><i class="fa fa-bars"></i></button>
										<?php }?>
											<button tabindex="-1" class="btn btn-warning" style="margin-left: 1px" type="submit"><i class="fa fa-refresh"></i></button>
											<button type="button" style="margin-left: 1px" tabindex="-1" class="btn btn-danger btn-delete-row" data-href="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=del_optionGrup&id=<?php echo $rs["id"];?>"><i class="fa fa-times"></i></button>
										</div>
									</td>
								</tr>
							</form>
						<?php }?>
					</table>
				</div>
			</div>
		</div>
	</div>
</body>
<?php echo $footer?>
</html>
<?php
$ss1 = isset($_GET["optionGrupID"]) ? $_GET["optionGrupID"] : 0;
$ss2 = isset($_POST["s2"]) ? $_POST["s2"] : 0;
$ss12 = isset($_POST["s12"]) ? $_POST["s12"] : 0;
if($_GET["durum"]=="add_optionGrup"){
	$sqlk=mysqli_query($conn, "select * from genel where ne='".$ne."' and n1='".$_POST["n1"]."'"); $rsk=mysqli_fetch_assoc($sqlk);
	if(mysqli_num_rows($sqlk)==0){
		$sql = $conn->query("INSERT INTO genel(ne, n1, s1, s2, s12) VALUES ('".$ne."', '".addslashes(stripslashes($_POST["n1"]))."', '".$ss1."', '".$ss2."', '".$ss12."')");
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&optionGrupID=".$_GET["optionGrupID"]."&durum=ok",self,500,1);
	}else{
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&optionGrupID=".$_GET["optionGrupID"]."&durum=err1",self,500,1);
	}

}elseif($_GET["durum"]=="update_optionGrup"){
	$Rs = mysqli_query($conn, "update genel set n1='".addslashes(stripslashes($_POST["n1"]))."', s1='".$ss1."', s2='".$ss2."', s12='".$ss12."' Where id=".$_GET["id"]."");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&optionGrupID=".$_GET["optionGrupID"]."&durum=ok",self,500,1);

}elseif($_GET["durum"]=="del_optionGrup"){
	$Rs = mysqli_query($conn, "delete from genel where id=".$_GET["id"]);
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&optionGrupID=".$_GET["optionGrupID"]."&durum=ok",self,500,1);  

}elseif($_GET["durum"]=="clear"){
	$Rs = mysqli_query($conn, "delete from genel where ne='".$ne."'");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&optionGrupID=".$_GET["optionGrupID"]."&durum=ok",self,500,1);  
}
?>