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

	echo " <div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
          <tr bgcolor='#2e2e2e'>
          	<th>No</th>
			<th>ID</th>
			<th>Nama Optik</th>
			<th>Alamat Lengkap</th>
			<th>Kota</th>
			<th>No Telpon</th>
			<th>Fax</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</th>
			<th style='border: none;'>Nama Optik</th>
			<th style='border: none;'>Alamat Lengkap</th>
			<th style='border: none;'>Kota</th>
			<th style='border: none;'>No Telpon</th>
			<th style='border: none;'>Fax</th>
			<th style='border: none;'>Keterangan</th>
			<th style='border: none;'></th>
		</tr>
	</tfoot>";
	echo "<tbody>";
	$no=1;
	$tampil = mysql_query("SELECT * FROM rb_data_optik ORDER BY id_data_optik 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_optik]</td>
		     <td>$r[nama_optik]</td>
		     <td>$r[alamat_optik]</td>
			 <td>$r[kota]</td>
			 <td>$r[telp]</td>
			 <td>$r[fax]</td>
			 <td>$r[keterangan]</td>
             <td><center><a class='linkkk' href=edit-optik-$r[id_data_optik].html>Edit</a>
			 <a class='linkkk' style='color:red' href=media.php?module=dataoptik&delete=$r[id_data_optik] onclick=\"return confirm('Anda yakin ingin hapus data ini?')\">X</a></center></td></tr>";
			 $no++;
		}
		if (isset($_GET[delete])){
			mysql_query("DELETE FROM rb_data_optik WHERE id_data_optik='$_GET[delete]'");
			echo "<script>document.location='optik.html';</script>";
		}
echo "	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='tambahdataoptik'){
	if (isset($_POST[submit])){
		mysql_query("INSERT INTO rb_data_optik(kode_optik,
                                 nama_optik,
								 alamat_optik,
								 kota,
								 telp,
								 fax,
								 keterangan) 
	                       VALUES('$_POST[kode_optik]',
                                '$_POST[nama_optik]',
								'$_POST[alamat_optik]',
								'$_POST[kota]',
								'$_POST[telp]',
								'$_POST[fax]',
								'$_POST[keterangan]')");
		echo "<script>document.location='optik.html';</script>";
	}
echo "<div class='post_title' style='margin-left:20%;'><b>Tambahkan Relasi Optik Baru.</b></div><hr><br/>
          <form method=POST action=''>
          <center><table width='60%'>
          <tr><td width='160px' class='td'><br>ID</td> <td class='td'><br/>:</td><td class='td'> <br><input type=text name='kode_optik' style='width:100%'></td></tr>  
          <tr><td class='td'>Nama Optik</td>   <td class='td'>:</td><td class='td'> <input type=text name='nama_optik' style='width:100%'></td></tr>
		  <tr><td class='td'>Alamat Lengkap</td>   <td class='td'>:</td><td class='td'> <textarea name='alamat_optik' style='width:100%; height:60px;'></textarea></td></tr>
		  <tr><td class='td'>Kota</td>   <td class='td'>:</td><td class='td'> <input type=text name='kota' style='width:50%'></td></tr>
		  <tr><td class='td'>No Telpon</td>   <td class='td'>:</td><td class='td'> <input type=text name='telp' style='width:50%'></td></tr>
		  <tr><td class='td'>Fax</td>   <td class='td'>:</td><td class='td'> <input type=text name='fax' style='width:50%'></td></tr>
		  <tr><td class='td'>Alamat Lengkap</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]=='editdataoptik'){
	if (isset($_POST[submit])){
		mysql_query("UPDATE rb_data_optik SET kode_optik  = '$_POST[kode_optik]', 
                                     nama_optik   = '$_POST[nama_optik]',
								     alamat_optik = '$_POST[alamat_optik]',
									 kota		  = '$_POST[kota]',
									 telp		  = '$_POST[telp]',
									 fax		  = '$_POST[fax]',
									 keterangan	  = '$_POST[keterangan]' 
                              WHERE  id_data_optik = '$_POST[id]'");
		echo "<script>document.location='optik.html';</script>";
	}
$edit=mysql_query("SELECT * FROM rb_data_optik WHERE id_data_optik='$_GET[id]'");
    $r=mysql_fetch_array($edit);
    echo "<div class='post_title' style='margin-left:20%;'><b>Edit Data '$r[nama_optik]'.</b></div><hr style='color:#e3e3e3;'><br/>
		 <div class='h_line'></div>
          <form method=POST action=''>
          <input type=hidden name=id value='$r[id_data_optik]'>
          <center><table width='60%'>
          <tr><td width='160px' class='td'><br>ID</td> <td class='td'><br/>:</td><td class='td'><br> <input type=text name='kode_optik' size=30  value='$r[kode_optik]' style='width:100%'></td></tr>
          <tr><td class='td'>Nama Optik</td>   <td class='td'>:</td><td class='td'> <input type=text name='nama_optik' size=30 value='$r[nama_optik]' style='width:100%'></td></tr>
		  <tr><td class='td'>Alamat Lengkap</td>   <td class='td'>:</td><td class='td'> <textarea name='alamat_optik' style='width:100%; height:60px;'>$r[alamat_optik]</textarea></td></tr>
		  <tr><td class='td'>Kota</td>   <td class='td'>:</td><td class='td'> <input type=text name='kota' size=30 value='$r[kota]' style='width:50%'></td></tr>
		  <tr><td class='td'>No Telpon</td>   <td class='td'>:</td><td class='td'> <input type=text name='telp' size=30 value='$r[telp]' style='width:50%'></td></tr>
		  <tr><td class='td'>Fax</td>   <td class='td'>:</td><td class='td'> <input type=text name='fax' size=30 value='$r[fax]' 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>";
		  
    echo "<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>";     
}