<?php
// Manage Dokter ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ($_GET[module]=='dokter'){
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>List atau Daftar Semua Dokter Pada Optik<hr></b></div>";
    echo "<input class='linkkk' type=button value='Tambah Dokter' onclick=\"window.location.href='tambah-dokter.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 Dokter</th>
			<th>No.Telepon/HP</th>
			<th>Resep Rp</th>
			<th>Alamat Lengkap</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 Dokter</th>
			<th style='border: none;'>No.Telepon/HP</th>
			<th style='border: none;'>Resep Rp</th>
			<th style='border: none;'>Alamat Lengkap</th>
			<th style='border: none;'>Keterangan</th>
			<th style='border: none;'></th>
		</tr>
	</tfoot>";
	echo "<tbody>";
	$no=1;
	$tampil = mysql_query("SELECT * FROM rb_dokter ORDER BY id_dokter 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_dokter]</td>
		     <td>$r[no_telpon]</td>
		     <td>Rp ".format_rupiah($r[resep_rp])."</td>
		     <td>$r[alamat]</td>
			 <td>$r[keterangan]</td>
             <td><center><a class='linkkk' href=edit-dokter-$r[id_dokter].html>Edit</a>
			 <a class='linkkk' style='color:red' href=media.php?module=dokter&delete=$r[id_dokter] onclick=\"return confirm('Anda yakin ingin hapus data ini?')\">X</a></center></td></tr>";
			 $no++;
		}
		if (isset($_GET[delete])){
			mysql_query("DELETE FROM rb_dokter WHERE id_dokter='$_GET[delete]'");
			echo "<script>document.location='dokter.html';</script>";
		}
echo "	
	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='tambahdokter'){
	if (isset($_POST[submit])){
		mysql_query("INSERT INTO rb_dokter(nama_dokter,
                                    no_telpon,
                                    resep_rp,
                    				alamat,
                    				keterangan) 
	                       VALUES('$_POST[nama_dokter]',
                                '$_POST[no_telp]',
                                '$_POST[resep]',
                				'$_POST[alamat_lengkap]',
                				'$_POST[keterangan]')");
		echo "<script>document.location='dokter.html';</script>";
	}	
echo "<div class='post_title' style='margin-left:20%;'><b>Tambahkan Dokter Baru.</b></div><hr><br/>
          <form method=POST action=''>
          <center><table width='60%'>
          <tr><td width='160px' class='td'><br>Nama Dokter</td> <td class='td'><br/>:</td><td class='td'> <br><input type=text name='nama_dokter' 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'>Resep Rp</td>   <td class='td'>:</td><td class='td'> <input type=text name='resep' style='width:30%'></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'>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]=='editdokter'){
	if (isset($_POST[submit])){
		mysql_query("UPDATE rb_dokter SET nama_dokter  = '$_POST[nama_dokter]', 
                                    no_telpon   = '$_POST[no_telp]',
                                    resep_rp   = '$_POST[resep]',
								    alamat		 = '$_POST[alamat_lengkap]',
									keterangan	 = '$_POST[keterangan]' 
                              WHERE  id_dokter = '$_POST[id]'");
		echo "<script>document.location='dokter.html';</script>";
	}	
$edit=mysql_query("SELECT * FROM rb_dokter WHERE id_dokter='$_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_dokter]'>
          <center><table width='60%'>
          <tr><td width='160px' class='td'><br>Nama Dokter</td> <td class='td'><br/>:</td><td class='td'><br> <input type=text name='nama_dokter' size=30  value='$r[nama_dokter]' 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'>Resep Rp</td>   <td class='td'>:</td><td class='td'> <input type=text name='resep' style='width:30%' value='$r[resep_rp]'></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'>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>";     
}