<?php
// Manage Produk ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ($_GET[module]=='produk'){
$detail=mysql_query("SELECT * FROM rb_kategori_produk where id_kategori='$_GET[id]'");
	$d   = mysql_fetch_array($detail);
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>List atau Daftar Semua $d[nama_kategori] Pada Optik<hr></b></div>";
    echo "<input class='linkkk' type=button value='Tambah $d[nama_kategori]' onclick=\"window.location.href='tambah-produk-$d[id_kategori].html';\">
		  <a style='float:right; color:red;' target='_BLANK' href='print_produk.php?id=$d[id_kategori]'>Print Data $d[nama_kategori]</a><hr>";
		
		  echo "<form style='float:right; margin-top:5px; margin-bottom:-5px; ' action='' method='POST'> 
				Cari $d[nama_kategori] : <input type=text name='produk'>
										 <input type=hidden name='kategori' value='$d[id_kategori]'>
				<input type=submit name='cari' value=cari>
			</form>";
		
	$cekp = mysql_num_rows(mysql_query("SELECT * FROM rb_kategori_produk where nama_kategori LIKE '%pesanan%' AND id_kategori='$_GET[id]'"));
	echo "<div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr><th></th>
			<th>No</th>
			<th width='80px'>no kode</th>
			<th width='80px'>kode</th>
			<th>Nama Produk</th>
			<th>Jenis</th>
			<th>Type</th>
            <th>Nama Distributor</th>
			<th width='100px'>Harga Jual</th>";
			if ($status == 'grosir' OR $status == 'admin'){
				echo "<th width='100px'>Harga Grosir</th>";
			}
			if ($status == 'admin'){
				echo "<th width='100px'>Harga Distributor</th>
					  <th width='100px'>Harga Modal</th>";
			}
            echo "<th>Warna</th>";
			if ($cekp <= 0){
				echo "<th>Stok</th>";
			}
			if ($status == 'admin'){
				echo "<th width='100px'>Total Modal</th>";
			}
			echo "<th style='text-align:center;'>Action</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th></th>
			<th style='border: none;'>No</th>
			<th style='border: none;'>No Kode</th>
			<th style='border: none;'>Kode</th>
			<th style='border: none;'>Nama Produk</th>
			<th style='border: none;'>Jenis</th>
			<th style='border: none;'>Type</th> 
            <th style='border: none;'>Nama Distributor</th>
			<th style='border: none;'>Harga Jual</th>";
			if ($status == 'grosir' OR $status == 'admin'){
				echo "<th style='border: none;'>Harga Grosir</th>";
			}
			if ($status == 'admin'){
				echo "<th style='border: none;'>Harga Distributor</th>
					  <th style='border: none;'>Harga Modal</th>";
			}
            echo "<th>Warna</th>";
			if ($cekp <= 0){
				echo "<th style='border: none;'>Stok</th>";
			}
			if ($status == 'admin'){
				echo "<th style='border: none;'>Total Modal</th>";
			}
			echo "<th style='border: none;'></th>
		</tr>
	</tfoot>";
	if (isset($_POST[cari])){
		$tampil = mysql_query("SELECT * FROM rb_produk a
	    							left join rb_supplier b on a.id_supplier=b.id_supplier 
										where a.id_kategori='$_GET[id]' AND a.nama_produk LIKE '$_POST[produk]%' ORDER BY id_produk DESC");
	}else{
		$tampil = mysql_query("SELECT * FROM rb_produk a
	    							left join rb_supplier b on a.id_supplier=b.id_supplier 
										where a.id_kategori='$_GET[id]' ORDER BY id_produk DESC");
	}
	$no = $posisi+1;
	echo "<tbody>";
    while($r=mysql_fetch_array($tampil)){
      	$tanggal=tgl_indo($r[tgl_masuk]);
      	$harga=format_rupiah($r[harga]);
	  	$harga_grosir=format_rupiah($r[harga_grosir]);
	  	$harga_pokok=format_rupiah($r[harga_pokok]);
	  	$harga_distributor=format_rupiah($r[harga_distributor]);
	  	$totpokok=$r[harga_pokok]*$r[stok];
	  	$totpokok_rp=format_rupiah($totpokok);
	  	if(($no % 2)==0){ $warna="#ffffff"; }else{ $warna="#E1E1E1"; }

	echo "<tr bgcolor='$warna'>
			<td width='5px'></td>
			<td class='read_only'>$no</td>
			<td style='color:blue'>$r[no_kode]</td>
			<td style='color:blue'>$r[kode_produk]</td>";
			$cekd = mysql_num_rows(mysql_query("SELECT * FROM rb_produk_detail where id_produk='$r[id_produk]'"));
			if ($cekd >= 1){
				$d = mysql_fetch_array(mysql_query("SELECT * FROM rb_produk_detail a 
													join rb_jenis b on a.id_jenis=b.id_jenis
	    												join rb_type c on a.id_type=c.id_type where a.id_produk='$r[id_produk]'"));
            	echo "<td class='linkSysteM'><a href='#' alt='Type : $d[type] - Jenis : $d[jenis]'>$r[nama_produk]</a>
            								 <a href='#' alt='SPH ($d[R_SPH]), CYL ($d[R_CYL]), AXS ($d[R_AXS]), ADD ($d[R_ADD]), PD ($d[PD])' style='background:#000; padding:2px 6px 2px 6px; color:#fff; text-decoration:none'>R</a>
            								 <a href='#' alt='SPH ($d[L_SPH]), CYL ($d[L_CYL]), AXS ($d[L_AXS]), ADD ($d[L_ADD]), PD ($d[PD2])' style='background:#000; padding:2px 6px 2px 6px; color:#fff; text-decoration:none'>L</a></td>";
                echo "<td >$d[jenis]</td>
                     <td >$d[type]</td>";
			}else{
				echo "<td>$r[nama_produk]</td><td></td><td></td>";
			}
			echo "<td>$r[nama_supplier]</td>            
            <td>Rp $harga</td>";
            if ($status == 'grosir' OR $status == 'admin'){
				echo "<td>Rp $harga_grosir</td>";
			}
			if ($status == 'admin'){
				echo "<td>Rp $harga_distributor</td>
					  <td>Rp $harga_pokok</td>";
			}
            echo "<td>$r[warna]</td>";
			if ($cekp <= 0){
				if ($r[stok]==0){
					echo "<td style='background:red; color:#fff; text-align:center;'>0</td>";
				}elseif ($r[stok]<=$r[warning]){
					echo "<td style='background:#f6c51c; color:#fff; text-align:center;'>$r[stok]</td>";
				}else{
					echo "<td style='text-align:center'>$r[stok]</td>";
				}
			}
			if ($status == 'admin'){
		        echo "<td>Rp $totpokok_rp</td>";
		    }
						echo "<td width='85'><center><a class='linkkk' href='edit-produk-$r[id_produk].html'>Edit</a>
		                <a class='linkkk' style='color:red' href='hapus-produk-$r[id_produk].html' onclick=\"return confirm('Anda yakin ingin hapus data ini?')\">X</a></center></td>
		</tr>";
		$no++;
		}
		if (isset($_POST[cari])){
			$sql = "SELECT SUM(harga) AS total_harga,
							SUM(harga_grosir) AS total_grosir,
							SUM(harga_pokok) AS total_pokokk,
							SUM(harga_pokok*stok) AS total_pokok,
							SUM(harga_distributor) AS total_distributor,
							SUM(stok) AS total_stok FROM rb_produk where id_kategori='$_GET[id]' AND nama_produk LIKE '$_POST[produk]%'";
		}else{
			$sql = "SELECT SUM(harga) AS total_harga,
							SUM(harga_grosir) AS total_grosir,
							SUM(harga_pokok) AS total_pokokk,
							SUM(harga_pokok*stok) AS total_pokok,
							SUM(harga_distributor) AS total_distributor,
							SUM(stok) AS total_stok FROM rb_produk where id_kategori='$_GET[id]'";
		}

		$result = mysql_query($sql) or die (mysql_error());
		$t = mysql_fetch_array($result);
		 $total_harga=format_rupiah($t[total_harga]);
		 $total_grosir=format_rupiah($t[total_grosir]);
		 $total_pokok_all=format_rupiah($t[total_pokok]);
		 $total_pokok=format_rupiah($t[total_pokokk]);
		 $total_distributor=format_rupiah($t[total_distributor]);
		 $total_stok=format_rupiah($t[total_stok]);

	echo "<tr style='border:1px solid $warna;'>

			<td style='background:$warna; color:$warna'>X</td>
			<td></td>
			<td></td>
			<td></td>
            <td></td>
			<td style='color:red; font-weight:bold;'>T o t a l</td>
            <td style='color:red'>Rp $total_harga</td><td></td><td></td>";
            if ($status == 'grosir' OR $status == 'admin'){
				echo "<td style='color:red'>Rp $total_grosir</td>";
			}
			if ($status == 'admin'){
				echo "<td style='color:red'>Rp $total_distributor</td>
					  <td style='color:red'>Rp $total_pokok</td>";
			}
            echo "<td></td>";
			if ($cekp <= 0){
				echo "<td style='color:red'>$total_stok</td>";
			}
			if ($status == 'admin'){
				echo "<td style='color:red'>$total_pokok_all</td>";
			}
			echo "<td></td></tr>
		</tbody></table>
</div></div>";
}

elseif ($_GET[module]=='tambahproduk'){
    $detail=mysql_query("SELECT * FROM rb_kategori_produk where id_kategori='$_GET[id]'");
    $cekp = mysql_num_rows(mysql_query("SELECT * FROM rb_kategori_produk where status='Ya' AND id_kategori='$_GET[id]'"));
	$d   = mysql_fetch_array($detail);
    echo "<div class='post_title' style='margin-left:20%;'><b>Tambah $d[nama_kategori].</b></div><hr><br/>
          <form method=POST action='aksi-tambahproduk.html' enctype='multipart/form-data'>
          <center><table width='60%' align='center'>
		  <tr><td width=130 class='td'>No Kode</td>     <td class='td' width='20px'>:</td><td class='td'><input type=text name='nokode' size=60 style='width:20%'></td></tr>
		  <tr><td width=130 class='td'>Kode Produk</td>     <td class='td' width='20px'>:</td><td class='td'><input type=text name='kode' size=60 style='width:20%'></td></tr>
          <tr><td class='td'>Nama Produk</td>     <td class='td'>:</td><td class='td'> <input type=text name='nama_produk' size=60 style='width:100%'></td></tr>";
          $tampil=mysql_query("SELECT * FROM rb_kategori_produk where id_kategori='$_GET[id]' ORDER BY nama_kategori");
          while($r=mysql_fetch_array($tampil)){
              echo "<input type=hidden name='kategori' value='$r[id_kategori]' size=60 style='width:99%'>";
          }
    echo "<tr><td class='td'>Harga Jual</td>    <td class='td'>:</td><td class='td'> <input type=text name='harga' style='width:50%'></td></tr>";
		  
		  if ($status == 'grosir' OR $status == 'admin'){
		  		echo "<tr><td class='td'>Harga Grosir</td>    <td class='td'>:</td><td class='td'> <input type=text name='harga_grosir' style='width:50%'></td></tr>";
		  }else{
		  		echo "<input type=hidden name='harga_grosir' value='0' style='width:50%'>";
		  }

		  if ($status == 'admin'){ 
			  	echo "<tr><td class='td'>Harga Distributor</td>    <td class='td'>:</td><td class='td'> <input type=text name='harga_distributor' style='width:50%'></td></tr>
			  		  <tr><td class='td'>Harga Modal</td>    <td class='td'>:</td><td class='td'> <input type=text name='harga_pokok' style='width:50%'></td></tr>";
          }else{	
          		echo "<input type=hidden name='harga_distributor' value='0' style='width:50%'>
          			  <input type=hidden name='harga_pokok' value='0' style='width:50%'>";
          }

          echo "<tr><td class='td'>Jumlah/Stok</td>     <td class='td'>:</td><td class='td'> <input type=text name='stok' style='width:20%'></td></tr>
		  		<tr><td class='td'>Nama Distributor</td>  	  <td class='td'>:</td><td class='td'><select name='supplier'>
            <option value=0 selected>- Pilih Nama Distributor -</option>";
            $tampil=mysql_query("SELECT * FROM rb_supplier ORDER BY nama_supplier");
            while($r=mysql_fetch_array($tampil)){
              echo "<option value=$r[id_supplier]>$r[nama_supplier]</option>";
            }
	echo "</select></td></tr>
		  <tr><td class='td'>Warna</td>     <td class='td'>:</td><td class='td'> <input type=text name='warna' style='width:10%'></td></tr>";
			if ($cekp >= 1){
					  echo "<tr><td class='td'>Type</td>     <td class='td'>:</td><td class='td'> <select name='type'>
			            <option value=0 selected>- Pilih type -</option>";
			            $tampil=mysql_query("SELECT * FROM rb_type ORDER BY id_type");
			            while($r=mysql_fetch_array($tampil)){
			              echo "<option value=$r[id_type]>$r[type]</option>";
			            }
						
				echo "</select></td></tr>
							<tr><td class='td'>Jenis</td>     <td class='td'>:</td><td class='td'> <select name='jenis'>
			            <option value=0 selected>- Pilih Jenis -</option>";
			            $tampil=mysql_query("SELECT * FROM rb_jenis ORDER BY id_jenis");
			            while($r=mysql_fetch_array($tampil)){
			              echo "<option value=$r[id_jenis]>$r[jenis]</option>";
			            }
						
				echo "</select></td></tr>
							<tr><td class='td'>Ukuran</td>     <td class='td'>:</td>";
							include "master/ukuran.php";
							echo "</tr>";
			}

			echo "<tr><td class='td'>Keterangan</td>   <td class='td'>:</td><td class='td'> <textarea name='keterangan' style='width:100%; height:60px;'></textarea></td></tr>";
		  echo "<tr><td colspan=3 class='td'><br/><input class='button-reply' type=button value=Batal onclick=self.history.back()>
							<input class='button-reply' type=submit value=Simpan></td></tr>
          </table></center></form><br/><br/><br/><br/>";
}

elseif ($_GET[module]=='aksitambahproduk'){
$cekp = mysql_num_rows(mysql_query("SELECT * FROM rb_kategori_produk where status='Ya' AND id_kategori='$_POST[kategori]'"));
if ($cekp >= 1){
    mysql_query("INSERT INTO rb_produk(kode_produk,no_kode,
									id_kategori,
									id_supplier,
									nama_produk,
                                    harga,
									harga_grosir,
									harga_pokok,
									harga_distributor,
                                    stok,
                                    warna,
                                    tgl_masuk,
									warning,
									keterangan) 
                            VALUES('$_POST[kode]',
								   '$_POST[nokode]',
								   '$_POST[kategori]',
								   '$_POST[supplier]',
								   '$_POST[nama_produk]',
                                   '$_POST[harga]',
                                   '$_POST[harga_grosir]',
                                   '$_POST[harga_pokok]',
								   '$_POST[harga_distributor]',
                                   '$_POST[stok]',
                                   '$_POST[warna]',
                                   '$tgl_sekarang',
								   '',
								   '$_POST[keterangan]')");
 $id_produk = mysql_insert_id();
 mysql_query("INSERT INTO rb_produk_detail (id_produk,
		  									id_jenis,
		  									id_type, 
											R_SPH, 
											L_SPH, 
											R_CYL, 
											L_CYL, 
											R_AXS, 
											L_AXS, 
											R_ADD, 
											L_ADD, 
											PD,
											PD2) 
									 VALUES('$id_produk',
											'$_POST[jenis]',
											'$_POST[type]',
											'$_POST[sph_r]',
											'$_POST[sph_l]', 
											'$_POST[cyl_r]',
											'$_POST[cyl_l]',
											'$_POST[axs_r]',
											'$_POST[axs_l]',
											'$_POST[add_r]', 
											'$_POST[add_l]', 
											'$_POST[pdr]',
											'$_POST[pdl]')");

}else{
    mysql_query("INSERT INTO rb_produk(kode_produk,no_kode,
									id_kategori,
									id_supplier,
									nama_produk,
                                    harga,
									harga_grosir,
									harga_pokok,
									harga_distributor,
                                    stok,
                                    warna,
                                    tgl_masuk,
									warning,
									keterangan) 
                            VALUES('$_POST[kode]',
                                    '$_POST[nokode]',
								   '$_POST[kategori]',
								   '$_POST[supplier]',
								   '$_POST[nama_produk]',
                                   '$_POST[harga]',
                                   '$_POST[harga_grosir]',
                                   '$_POST[harga_pokok]',
								   '$_POST[harga_distributor]',
                                   '$_POST[stok]',
                                   '$_POST[warna]',
                                   '$tgl_sekarang',
								   '',
								   '$_POST[keterangan]')");
}
		
echo "<script>window.alert('$_POST[nama_produk] telah berhasil di tambahkan.');
				window.location='produk-$_POST[kategori].html'</script>";	
}

elseif ($_GET[module]=='editproduk'){
	$edit = mysql_query("SELECT a.*, b.id_jenis, b.id_type, b.R_SPH, b.L_SPH, b.R_CYL, b.L_CYL, b.R_AXS, b.L_AXS, b.R_ADD, b.L_ADD, b.PD, b.PD2 
								FROM rb_produk a LEFT JOIN rb_produk_detail b ON a.id_produk=b.id_produk WHERE a.id_produk='$_GET[id]'");
    $r    = mysql_fetch_array($edit);
	$cekp = mysql_num_rows(mysql_query("SELECT * FROM rb_kategori_produk where status='Ya' AND id_kategori='$r[id_kategori]'"));
    echo "<div class='post_title' style='margin-left:20%;'><b>Edit $r[nama_produk].</b></div><hr><br/>
          <form method=POST enctype='multipart/form-data' action='aksi-editproduk.html'>
          <input type=hidden name=id value=$r[id_produk]>
          <input type=hidden name=kategori value=$r[id_kategori]>
          <center><table width='60%'>
		  <input type=hidden name='kategori' value='$r[id_kategori]' size=60 style='width:99%'>
          <tr><td class='td' width=140>No Kode</td><td class='td' width='20px'>:</td><td class='td'> <input type=text name='nokode' size=60 style='width:20%' value='$r[no_kode]'></td></tr>
          <tr><td class='td' width=140>Kode Produk</td><td class='td' width='20px'>:</td><td class='td'> <input type=text name='kode' size=60 style='width:20%' value='$r[kode_produk]'></td></tr>
          <tr><td class='td'>Nama Produk</td>    <td class='td'>:</td> <td class='td'> <input type=text name='nama_produk' size=60 style='width:100%' value='$r[nama_produk]'></td></tr>
		  <tr><td class='td'>Harga Jual</td>   <td class='td'>:</td> <td class='td'> <input type=text name='harga' value='$r[harga]' style='width:50%'></td></tr>";
		  if ($status == 'grosir' OR $status == 'admin'){ 
		  		echo "<tr><td class='td'>Harga Grosir</td>   <td class='td'>:</td> <td class='td'> <input type=text name='harga_grosir' value='$r[harga_grosir]' style='width:50%'></td></tr>";
		  }else{		
		  		echo "<input type=hidden name='harga_grosir' value='$r[harga_grosir]' style='width:50%'>";
		  }

		  if ($status == 'admin'){ 
		  echo "<tr><td class='td'>Harga Distributor</td>   <td class='td'>:</td> <td class='td'> <input type=text name='harga_distributor' value='$r[harga_distributor]' style='width:50%'></td></tr>
		  		<tr><td class='td'>Harga Modal</td>   <td class='td'>:</td> <td class='td'> <input type=text name='harga_pokok' value='$r[harga_pokok]' style='width:50%'></td></tr>";
          }else{		
          		echo "<input type=hidden name='harga_distributor' value='$r[harga_distributor]' style='width:50%'>
          			  <input type=hidden name='harga_pokok' value='$r[harga_pokok]' style='width:50%'>";
          }
          echo "<tr><td class='td'>Jumlah/Stok</td>    <td class='td'>:</td> <td class='td'> <input type=text name='stok' value='$r[stok]' style='width:20%'></td></tr>
		  		<tr><td class='td'>Nama Distributor</td>  <td class='td'>:</td> <td class='td'> <select name='supplier'>";
 
          $tampil=mysql_query("SELECT * FROM rb_supplier ORDER BY nama_supplier");
          if ($r[id_supplier]==0){
            echo "<option value=0 selected>- Pilih Nama Distributor -</option>";
          }   

          while($w=mysql_fetch_array($tampil)){
            if ($r[id_supplier]==$w[id_supplier]){
              echo "<option value=$w[id_supplier] selected>$w[nama_supplier]</option>";
            }
            else{
              echo "<option value=$w[id_supplier]>$w[nama_supplier]</option>";
            }
          }
    echo "</select></td></tr>
		  <tr><td class='td'>Warning</td>     <td class='td'>:</td><td class='td'> <input type=text name='warning' value='$r[warning]' style='width:10%'></td></tr>";
if ($cekp >= 1){
		  echo "<tr><td class='td'>Type</td>     <td class='td'>:</td><td class='td'> <select name='type'>";
 
          $tampil=mysql_query("SELECT * FROM rb_type ORDER BY type");
          echo "<option value=0 selected>- Pilih Type -</option>";
          while($w=mysql_fetch_array($tampil)){
            if ($r[id_type]==$w[id_type]){
              echo "<option value=$w[id_type] selected>$w[type]</option>";
            }else{
              echo "<option value=$w[id_type]>$w[type]</option>";
            }
          }
    echo "</select></td></tr>
				<tr><td class='td'>Jenis</td>     <td class='td'>:</td><td class='td'> <select name='jenis'>";
          $tampil=mysql_query("SELECT * FROM rb_jenis ORDER BY jenis");
          echo "<option value=0 selected>- Pilih jenis -</option>";
          while($w=mysql_fetch_array($tampil)){
            if ($r[id_jenis]==$w[id_jenis]){
              echo "<option value=$w[id_jenis] selected>$w[jenis]</option>";
            }else{
              echo "<option value=$w[id_jenis]>$w[jenis]</option>";
            }
          }
    echo "</select></td></tr>
				<tr><td class='td'>Ukuran</td>     <td class='td'>:</td>";
					include "master/ukuran.php";
				echo "</tr>";
}
		  echo "<tr><td class='td'>Keterangan</td>   <td class='td'>:</td><td class='td'> <textarea name='keterangan' style='width:100%; height:60px;'>$r[keterangan]</textarea></td></tr>";
		  echo "<tr><td class='td' colspan=3><input class='button-reply' type=button value=Batal onclick=self.history.back()>
							<input class='button-reply' type=submit value=Update></td></tr>
         </table></center></form>";
}

elseif ($_GET[module]=='aksieditproduk'){
$cekp = mysql_num_rows(mysql_query("SELECT * FROM rb_kategori_produk where status='Ya' AND id_kategori='$_POST[kategori]'"));
if ($cekp >= 1){
    mysql_query("UPDATE rb_produk SET kode_produk  = '$_POST[kode]',
								   no_kode   = '$_POST[nokode]',
								   id_kategori   = '$_POST[kategori]',
								   id_supplier   = '$_POST[supplier]',
								   nama_produk   = '$_POST[nama_produk]',
                                   harga         = '$_POST[harga]',
								   harga_grosir  = '$_POST[harga_grosir]',
								   harga_pokok   = '$_POST[harga_pokok]',
								   harga_distributor   = '$_POST[harga_distributor]',
                                   stok          = '$_POST[stok]',
								   warning       = '$_POST[warning]',
								   keterangan    = '$_POST[keterangan]' WHERE id_produk = '$_POST[id]'");

    $lensacek = mysql_num_rows(mysql_query("SELECT * FROM rb_produk_detail where id_produk='$_POST[id]'"));
    if ($lensacek >= 1){
    	mysql_query("UPDATE rb_produk_detail SET id_jenis = '$_POST[jenis]',
    											 id_type = '$_POST[type]',
												 R_SPH = '$_POST[sph_r]', 
												 L_SPH = '$_POST[sph_l]',
												 R_CYL = '$_POST[cyl_r]',
												 L_CYL = '$_POST[cyl_l]',
												 R_AXS = '$_POST[axs_r]',
												 L_AXS = '$_POST[axs_l]',
												 R_ADD = '$_POST[add_r]', 
												 L_ADD = '$_POST[add_l]', 
												 PD = '$_POST[pdr]',
												 PD2 = '$_POST[pdl]' WHERE id_produk = '$_POST[id]'");
    }else{
    	mysql_query("INSERT INTO rb_produk_detail (id_produk,
				  									id_jenis,
				  									id_type, 
													R_SPH, 
													L_SPH, 
													R_CYL, 
													L_CYL, 
													R_AXS, 
													L_AXS, 
													R_ADD, 
													L_ADD, 
													PD,
													PD2) 
											 VALUES('$_POST[id]',
													'$_POST[jenis]',
													'$_POST[type]',
													'$_POST[sph_r]',
													'$_POST[sph_l]', 
													'$_POST[cyl_r]',
													'$_POST[cyl_l]',
													'$_POST[axs_r]',
													'$_POST[axs_l]',
													'$_POST[add_r]', 
													'$_POST[add_l]', 
													'$_POST[pdr]',
													'$_POST[pdl]')");
    }


}else{
    mysql_query("UPDATE rb_produk SET kode_produk  = '$_POST[kode]',
                                     no_kode   = '$_POST[nokode]',
								   id_kategori   = '$_POST[kategori]',
								   id_supplier   = '$_POST[supplier]',
								   nama_produk   = '$_POST[nama_produk]',
                                   harga         = '$_POST[harga]',
								   harga_grosir  = '$_POST[harga_grosir]',
								   harga_pokok   = '$_POST[harga_pokok]',
								   harga_distributor   = '$_POST[harga_distributor]',
                                   stok          = '$_POST[stok]',
								   warning       = '$_POST[warning]',
								   keterangan    = '$_POST[keterangan]'
                             WHERE id_produk     = '$_POST[id]'");
}	
	echo "<script>window.alert('$_POST[nama_produk] telah berhasil di Update.');
				window.location='produk-$_POST[kategori].html'</script>";	
}

elseif ($_GET[module]=='hapusproduk'){
  $detail=mysql_query("SELECT * FROM rb_produk where id_produk='$_GET[id]'");
  $d   = mysql_fetch_array($detail);
  mysql_query("DELETE FROM rb_produk WHERE id_produk='$_GET[id]'");

  echo "<script>window.alert('Sukses Menghapus $d[nama_produk].');
				window.location='produk-$d[id_kategori].html'</script>";	
}