<?php 
include"inc/vt.php";
$durum=$_POST["durum"];
if ($durum=="alerjisecenek") {

	$secenek	=	$_POST["alerji"];

	$alerjik = $dbh->prepare("SELECT * FROM allergy where title=? ");
	$alerjik-> execute(array($secenek));
	$alerjik= $alerjik->fetch(PDO::FETCH_OBJ);
	if(empty($alerjik)){


		$insert	=	$dbh->prepare("INSERT INTO allergy SET title=?,description=?,foto=?" );
		$insert-> execute(array($secenek,"as","de"));

		$alerjikid = $dbh->prepare("SELECT * FROM allergy WHERE  title=? ");
		$alerjikid-> execute(array($secenek));
		$alerjikid= $alerjikid->fetch(PDO::FETCH_OBJ);

		$cevap = array(
			"onay" => 	"1",
			"id" => 	$alerjikid->id,
		);

	}else{
		$cevap = array(
			"onay" => 	"2",
		);

	}


	echo json_encode($cevap);
}


if ($durum=="eksecenekekle") {

	$secenek	=	$_POST["eksecenek"];

	$secilebilir = $dbh->prepare("SELECT * FROM selectable WHERE  option=? ");
	$secilebilir-> execute(array($secenek));
	$secilebilir= $secilebilir->fetch(PDO::FETCH_OBJ);
	if(empty($secilebilir)){


		$insert	=	$dbh->prepare("INSERT INTO selectable SET option=?");
		$insert-> execute(array($secenek));

		$secilebilirid = $dbh->prepare("SELECT * FROM selectable WHERE option=? ");
		$secilebilirid-> execute(array($secenek));
		$secilebilirid= $secilebilirid->fetch(PDO::FETCH_OBJ);

		$cevap = array(
			"onay" => 	"1",
			"id" => 	$secilebilirid->id,
		);

	}else{
		$cevap = array(
			"onay" => 	"2",
		);
	}
	echo json_encode($cevap);
}



if ($durum=="porsiyonekle") {

	$secenek	=	$_POST["secenek"];
	if(!empty($secenek)){

		$secilebilir = $dbh->prepare("SELECT * FROM product_portion WHERE  portion=? ");
		$secilebilir-> execute(array($secenek));
		$secilebilir= $secilebilir->fetch(PDO::FETCH_OBJ);
		if(empty($secilebilir)){


			$insert	=	$dbh->prepare("INSERT INTO product_portion SET portion=?");
			$insert-> execute(array($secenek));

			$secilebilirid = $dbh->prepare("SELECT * FROM product_portion WHERE  portion=? ");
			$secilebilirid-> execute(array($secenek));
			$secilebilirid= $secilebilirid->fetch(PDO::FETCH_OBJ);

			$cevap = array(
				"onay" => 	"1",
				"idd" => 	$secilebilirid->id,
			);

		}else{
			$cevap = array(
				"onay" => 	"2",
			);
		}
	}else{
		$cevap = array(
			"onay" => 	"3",
		);
	}
	echo json_encode($cevap);
}

if ($durum=="seceneksecid") { 

	$id=$_POST['id'];
	?>

	<div class="col-lg-4" id="sitem<?=$id?>" style="padding-bottom:10px ">
		<div class="row"> 

			<div class="col-md-1 col-sm-1 col-xs-1">
				<a id="item<?=$id;?>"  onclick="delitem(this.id)" aria-hidden="true" style="font-size: 25px;
				color: red;cursor:pointer;">×</a>
			</div>
			<div class="col-md-8 col-sm-8 col-xs-8">

				<select class="form-control" name="secenek[]" id="secenek" >
					<option value="0" >Seçenek Seçiniz</option>
					<?php	
					$secilebilirsecenek = $dbh->prepare("SELECT * FROM product_portion  where status=1 order by portion asc");
					$secilebilirsecenek-> execute(array());
					$secilebilirsecenek= $secilebilirsecenek->fetchAll(PDO::FETCH_OBJ);

					foreach ($secilebilirsecenek as $secenek) {  ?>

						<option <?php if($secenek->id==$id){echo"selected";} ?> value="<?=$secenek->id;?>" ><?=$secenek->portion?></option>

					<?php  } ?>
				</select>
			</div>
			<div class="col-md-3 col-sm-3 col-xs-3">
				<input type="number" name="secenekfiyat[]"  min="0" class="form-control" placeholder="10" style="width: 64px;">
			</div>
		</div>
	</div>

<?php 	} 


if ($durum=="seceneksec") { 

	$id=rand(1,10000);
	?>

	<div class="col-lg-4" id="sitem<?=$id?>" style="padding-bottom:10px ">
		<div class="row"> 

			<div class="col-md-1 col-sm-1 col-xs-1">
				<a id="item<?=$id;?>"  onclick="delitem(this.id)" aria-hidden="true" style="font-size: 25px;
				color: red;cursor:pointer;">×</a>
			</div>
			<div class="col-md-8 col-sm-8 col-xs-8">

				<select class="form-control" name="secenek[]" id="secenek" >
					<option value="0" >Seçenek Seçiniz</option>
					<?php	
					$secilebilirsecenek = $dbh->prepare("SELECT * FROM product_portion where status=1 order by portion asc");
					$secilebilirsecenek-> execute(array());
					$secilebilirsecenek= $secilebilirsecenek->fetchAll(PDO::FETCH_OBJ);

					foreach ($secilebilirsecenek as $secenek) {  ?>

						<option <?php if($secenek->id==$id){echo"selected";} ?> value="<?=$secenek->id;?>" ><?=$secenek->portion?></option>

					<?php  } ?>
				</select>
			</div>
			<div class="col-md-3 col-sm-3 col-xs-3">
				<input type="number" name="secenekfiyat[]"  min="0" class="form-control" placeholder="10" style="width: 64px;">
			</div>
		</div>
	</div>

	<?php 	} ?>