<?php
// Manage Distributor ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ($_GET[module]=='distributor'){
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>List atau Daftar Semua Distributor Pada Optik<hr></b></div>";
    echo "<input class='linkkk' type=button value='Tambah Distributor' onclick=\"window.location.href='tambah-distributor.html';\">
          <hr>";

	echo " <div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
          <tr bgcolor='#2e2e2e'>
			<th width='20px'>No</th>
			<th>Id Distributor</th>
			<th>Nama Distributor</th>
			<th>No.Telepon/HP</th>
			<th>Alamat Lengkap</th>
			<th>Nama Sales</th>
			<th>Keterangan</th>
			<th style='width:100px; text-align:center;'>Action</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>No</th>
			<th style='border: none;'>Id Distributor</th>
			<th style='border: none;'>Nama Distributor</th>
			<th style='border: none;'>No.Telepon/HP</th>
			<th style='border: none;'>Alamat Lengkap</th>
			<th style='border: none;'>Nama Sales</th>
			<th style='border: none;'>Keterangan</th>
			<th style='border: none;'></th>
		</tr>
	</tfoot>";
	echo "<tbody>";
	$no=1;
	$tampil = mysql_query("SELECT * FROM rb_supplier ORDER BY id_supplier DESC");
    while($r=mysql_fetch_array($tampil)){
	  if(($no % 2)==0){ $warna="#ffffff"; }else{ $warna="#E1E1E1"; }
       echo "<tr bgcolor=$warna><td class='read_only'>$no</td>
			 <td>$r[kode_supplier]</td>
             <td>$r[nama_supplier]</td>
		     <td>$r[no_telp]</td>
		     <td>$r[alamat_lengkap]</td>
			 <td>$r[sales]</td>
			 <td>$r[keterangan]</td>
             <td><center><a class='linkkk' href=edit-distributor-$r[id_supplier].html>Edit</a>
			 <a class='linkkk' style='color:red' href='media.php?module=kategori&delete=$r[id_supplier]' onclick=\"return confirm('Anda yakin ingin hapus data ini?')\">X</a></center></td></tr>";
			 $no++;
		}
		if (isset($_GET[delete])){
			mysql_query("DELETE FROM rb_supplier WHERE id_supplier='$_GET[delete]'");
			echo "<script>document.location='distributor.html';</script>";
		}
echo "	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='tambahdistributor'){
	if (isset($_POST[submit])){
		mysql_query("INSERT INTO rb_supplier(kode_supplier,
								 nama_supplier,
                                 no_telp,
								 alamat_lengkap,
								 sales,
								 keterangan) 
	                       VALUES('$_POST[kode_supplier]',
								'$_POST[nama_supplier]',
                                '$_POST[no_telp]',
								'$_POST[alamat_lengkap]',
								'$_POST[sales]',
								'$_POST[keterangan]')");
		echo "<script>document.location='distributor.html';</script>";
	}
echo "<div class='post_title' style='margin-left:20%;'><b>Tambahkan Distributor Baru.</b></div><hr><br/>
          <form method=POST action=''>
          <center><table width='60%'>
		  <tr><td width='160px' class='td'><br>Id Distributor</td> <td class='td'><br/>:</td><td class='td'> <br><input type=text name='kode_supplier' style='width:50%'></td></tr>
          <tr><td class='td'>Nama Distributor</td> <td class='td'>:</td><td class='td'> <input type=text name='nama_supplier' style='width:50%'></td></tr>  
          <tr><td class='td'>No.Telepon/HP</td>   <td class='td'>:</td><td class='td'> <input type=text name='no_telp' style='width:50%'></td></tr>
		  <tr><td class='td'>Alamat Lengkap</td>   <td class='td'>:</td><td class='td'><textarea name='alamat_lengkap' style='width:100%; height:60px;'></textarea></td></tr>
		  <tr><td class='td'>Nama Sales</td>   <td class='td'>:</td><td class='td'> <input type=text name='sales' style='width:50%'></td></tr>
		   <tr><td class='td'>Keterangan</td>   <td class='td'>:</td><td class='td'> <textarea name='keterangan' style='width:100%; height:60px;'></textarea></td></tr>
          <tr><td class='td' colspan=3><br/><input class='button-reply' type=button value=Batal onclick=self.history.back()>
							<input name='submit' class='button-reply' type=submit value=Simpan></td></tr>
          </table></center></form>";
}

elseif ($_GET[module]=='editdistributor'){
	if (isset($_POST[submit])){
		mysql_query("UPDATE rb_supplier SET kode_supplier  = '$_POST[kode_supplier]', 
									 nama_supplier  = '$_POST[nama_supplier]', 
                                     no_telp        = '$_POST[no_telp]',
								     alamat_lengkap = '$_POST[alamat_lengkap]',
									 sales		    = '$_POST[sales]',
									 keterangan		= '$_POST[keterangan]' 
                              WHERE  id_supplier    = '$_POST[id]'");
		echo "<script>document.location='distributor.html';</script>";
	}
$edit=mysql_query("SELECT * FROM rb_supplier WHERE id_supplier='$_GET[id]'");
    $r=mysql_fetch_array($edit);
    echo "<div class='post_title' style='margin-left:20%;'><b>Edit Data '$r[nama_supplier]' (Distributor).</b></div><hr style='color:#e3e3e3;'><br/>
		 <div class='h_line'></div>
          <form method=POST action=''>
          <input type=hidden name=id value='$r[id_supplier]'>
          <center><table width='60%'>
		  <tr><td width='160px' class='td'><br>Id Distributor</td> <td class='td'><br/>:</td><td class='td'><br> <input type=text name='kode_supplier' size=30  value='$r[kode_supplier]' style='width:50%'></td></tr>
          <tr><td class='td'>Nama Distributor</td> <td class='td'>:</td><td class='td'><input type=text name='nama_supplier' size=30  value='$r[nama_supplier]' style='width:50%'></td></tr>
          <tr><td class='td'>No.Telepon/HP</td>   <td class='td'>:</td><td class='td'> <input type=text name='no_telp' size=30 value='$r[no_telp]' style='width:50%'></td></tr>
		  <tr><td class='td'>Alamat Lengkap</td>   <td class='td'>:</td><td class='td'> <textarea name='alamat_lengkap' style='width:100%; height:60px;'>$r[alamat_lengkap]</textarea></td></tr>
		  <tr><td class='td'>Nama Sales</td>   <td class='td'>:</td><td class='td'> <input type=text name='sales' size=30 value='$r[sales]' style='width:50%'></td></tr>
		   <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>
		  
		  <tr><td class='td' colspan=3><br/><input class='button-reply' type=button value=Batal onclick=self.history.back()>
									   <input name='submit' class='button-reply' type=submit value=Update></td></tr>
          </table></center></form>";     
}