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

	echo " <div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
          <tr bgcolor='#2e2e2e'>
			<th width='20px'>No</th>
			<th>Nama Instansi</th>
			<th>No.Telepon/HP</th>
			<th>Alamat Lengkap</th>
			<th>Harga/Nilai</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;'>Nama Instansi</th>
			<th style='border: none;'>No.Telepon/HP</th>
			<th style='border: none;'>Alamat Lengkap</th>
			<th style='border: none;'>Harga/Nilai</th>
			<th style='border: none;'>Keterangan</th>
			<th style='border: none;'></th>
		</tr>
	</tfoot>";
	echo "<tbody>";
	$no=1;
	$tampil = mysql_query("SELECT * FROM rb_instansi ORDER BY id_instansi 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[nama_instansi]</td>
		     <td>$r[no_telpon]</td>
		     <td>$r[alamat]</td>
			 <td>Rp $r[harga]</td>
			 <td>$r[keterangan]</td>
             <td><center><a class='linkkk' href=edit-instansi-$r[id_instansi].html>Edit</a>
			 <a class='linkkk' style='color:red' href=media.php?module=instansi&delete=$r[id_instansi] onclick=\"return confirm('Anda yakin ingin hapus data ini?')\">X</a></center></td></tr>";
			 $no++;
		}
		if (isset($_GET[delete])){
			mysql_query("DELETE FROM rb_instansi WHERE id_instansi='$_GET[delete]'");
			echo "<script>document.location='instansi.html';</script>";
		}
echo "	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='tambahinstansi'){
	if (isset($_POST[submit])){
		mysql_query("INSERT INTO rb_instansi(nama_instansi,
                                 no_telpon,
								 alamat,
								 harga,
								 keterangan) 
	                       VALUES('$_POST[nama_instansi]',
                                '$_POST[no_telp]',
								'$_POST[alamat_lengkap]',
								'$_POST[harga]',
								'$_POST[keterangan]')");
		echo "<script>document.location='instansi.html';</script>";
	}
echo "<div class='post_title' style='margin-left:20%;'><b>Tambahkan Instansi Baru.</b></div><hr><br/>
          <form method=POST action=''>
          <center><table width='60%'>
          <tr><td width='160px' class='td'><br>Nama Instansi</td> <td class='td'><br/>:</td><td class='td'> <br><input type=text name='nama_instansi' 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'>Harga/Nilai</td>   <td class='td'>:</td><td class='td'> <input type=text name='harga' 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]=='editinstansi'){
	if (isset($_POST[submit])){
		mysql_query("UPDATE rb_instansi SET nama_instansi  = '$_POST[nama_instansi]', 
                                     no_telpon   = '$_POST[no_telp]',
								     alamat		 = '$_POST[alamat_lengkap]',
									 harga		 = '$_POST[harga]',
									 keterangan	 = '$_POST[keterangan]'
                              WHERE  id_instansi = '$_POST[id]'");
		echo "<script>document.location='instansi.html';</script>";
	}
$edit=mysql_query("SELECT * FROM rb_instansi WHERE id_instansi='$_GET[id]'");
    $r=mysql_fetch_array($edit);
    echo "<div class='post_title' style='margin-left:20%;'><b>Edit Data '$r[nama_dokter]' (Dokter).</b></div><hr style='color:#e3e3e3;'><br/>
		 <div class='h_line'></div>
          <form method=POST action=''>
          <input type=hidden name=id value='$r[id_instansi]'>
          <center><table width='60%'>
          <tr><td width='160px' class='td'><br>Nama Instansi</td> <td class='td'><br/>:</td><td class='td'><br> <input type=text name='nama_instansi' size=30  value='$r[nama_instansi]' 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_telpon]' 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]</textarea></td></tr>
		  <tr><td class='td'>Harga/Nilai</td>   <td class='td'>:</td><td class='td'> <input type=text name='harga' value='$r[harga]' 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>";     
}