<?php
include('config.php');

$autoid = $_POST['autoid'];
$gl 	= $_POST['gl'];
$jb 	= $_POST['jb'];
$mp 	= $_POST['mp'];
$jj 	= $_POST['jj'];
$ff 	= $_POST['ff'];
$kelas = $_POST['kelas'];
$act 	= $_POST['act'];
$kl 	= $_POST['kl'];
$tipe 	= $_POST['tipe'];
$cat_id = $_POST['cat_id'];
$sub_jb1 = $_POST['sub_jb1'];
$sub_jb2 = $_POST['sub_jb2'];
$sub_jb3 = $_POST['sub_jb3'];


if($act==1){
$sql = "INSERT INTO 
		dl_product_category 
		(product_id,gl_autoid,ff_flag,jj_autoid,mp_autoid,jb_autoid,kelas,kl_autoid,tipe_buku) 
		VALUES 
		('$autoid','$gl','$ff','$jj','$mp','$jb','$kelas','$kl','$tipe')";
$conn->query($sql) or die($sql);

if($sub_jb1){
	$sql = "INSERT INTO 
		dl_product_category 
		(product_id,gl_autoid,ff_flag,jj_autoid,mp_autoid,jb_autoid,kelas,kl_autoid,tipe_buku) 
		VALUES 
		('$autoid','$gl','$ff','$jj','$mp','$sub_jb1','$kelas','$kl','$tipe')";
		$conn->query($sql) or die($sql);
	}
if($sub_jb2){
	$sql = "INSERT INTO 
		dl_product_category 
		(product_id,gl_autoid,ff_flag,jj_autoid,mp_autoid,jb_autoid,kelas,kl_autoid,tipe_buku) 
		VALUES 
		('$autoid','$gl','$ff','$jj','$mp','$sub_jb2','$kelas','$kl','$tipe')";
		$conn->query($sql) or die($sql);
	}
if($sub_jb3){
	$sql = "INSERT INTO 
		dl_product_category 
		(product_id,gl_autoid,ff_flag,jj_autoid,mp_autoid,jb_autoid,kelas,kl_autoid,tipe_buku) 
		VALUES 
		('$autoid','$gl','$ff','$jj','$mp','$sub_jb3','$kelas','$kl','$tipe')";
		$conn->query($sql) or die($sql);
	}

}
if($act==99){
	$sql = "DELETE FROM dl_product_category WHERE cat_autoid = '$cat_id'";
	$conn->query($sql) or die($sql);
	}


$sqln = "SELECT * FROM dl_product_category WHERE product_id = '$autoid'";
$dcon = $conn->query($sqln) or die($sqln);
//echo $sqln;
while($rs = $dcon->fetch_array()){
	$golongan 	= $gol_name[$rs['gl_autoid']]; 
	$mapel 		= $mp_name[$rs['mp_autoid']];
	$jenisbuku 	= $jb_name[$rs['jb_autoid']];
	$jenjang 	= $jj_name[$rs['jj_autoid']];
	$koleksi = $kl_name[$rs['kl_autoid']];
	
	if($koleksi){$koleksi = " - ".$koleksi;}
	if($mapel){$mapel = " - ".$mapel;}
	if($jenisbuku){$jenisbuku = " - ".$jenisbuku;}
	if($jenjang){$jenjang = " - ".$jenjang;}
	
	if($rs['tipe_buku']==1){$tipebuku = "  - Buku Siswa";}
	else if($rs['tipe_buku']==2){$tipebuku = "  - Buku Guru";}
	else{$tipebuku = "";}
	if($rs['kelas']!=0){$kelas = " - Kelas ".$rs['kelas'];}
?>
<div class="prod_cat_div" style="color:black">
	
	<?php echo $golongan?> <?php echo $koleksi?> <?php echo $jenisbuku?> <?php echo $jenjang?> <?php echo $mapel?> <?php echo $kelas?>  <?php echo $tipebuku?> 
    <img src="../../image/del.png" class="del_icon" title="Hapus Kategori" onclick="del_category('<?php echo $rs['cat_autoid']?>')"/>
</div>
<?php	} ?>