<?php
// Manage Karyawan ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ($_GET[module]=='laplensapesanan'){
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>List Laporan/Catatan Lensa Pesanan<hr></b></div>";
    echo "<input class='linkkk' type=button value='Tambah Laporan Pesanan' onclick=\"window.location.href='media.php?module=tambahlaplensapesanan';\">
          <hr>";

	echo " <div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
          <tr bgcolor='#2e2e2e'>
			<th>No</th>
			<th>Tgl Pesan</th>
			<th>No PO</th>
			<th>Distributor</th>
			<th>Nama Konsumen</th>
			<th>Jenis Lensa</th>
			<th>Ukuran</th>
			<th>Tgl Sampai</th>
			<th>Memo</th>";
			if ($status == 'admin'){
				echo "<th style='width:100px; text-align:center;'>Action</th>";
			}
		echo "</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>No</th>
			<th style='border: none;'>Tgl Pesan</th>
			<th style='border: none;'>No PO</th>
			<th style='border: none;'>Distributor</th>
			<th style='border: none;'>Nama Konsumen</th>
			<th style='border: none;'>Jenis Lensa</th>
			<th style='border: none;'>Nama Lensa</th>
			<th style='border: none;'>Tgl Sampai</th>
			<th style='border: none;'>Memo</th>";
			if ($status == 'admin'){
				echo "<th style='border: none;'></th>";
			}
		echo "</tr>
	</tfoot>";
	echo "<tbody>";
	$no=1;
	$tampil = mysql_query("SELECT * FROM rb_laporan_pesanan a JOIN rb_ukuran b ON a.jenis_lensa=b.id_ukuran ORDER BY a.id_laporan_pesanan");
    while($p=mysql_fetch_array($tampil)){
	  if(($no % 2)==0){
			$warna="#ffffff";
		  }
		  else{
			$warna="#E1E1E1";
		  }
		
			echo "<tr bgcolor=$warna><td class='read_only'>$no</td>
			 <td>".tgl_indo($p[tgl_pesan])."</td>
             <td>$p[no_po]</td>
			 <td>$p[distributor]</td>
		     <td>$p[nama_konsumen]</td>
		     <td class='linkSysteM'><a href='#' alt='$p[keterangan]'>$p[ukuran]</a></td>
		     <td width='345px'>"; include "master/ukuran_pesanan.php"; 
		     echo "</td><td>".tgl_indo($p[tgl_sampai])."</td>
		     <td>$p[extion]</td>";
		     if ($status == 'admin'){
			     echo "<td><center><a class='linkkk' href='media.php?module=editlaplensapesanan&id=$p[id_laporan_pesanan]'>Edit</a>
				 <a class='linkkk' style='color:red' href='media.php?module=laplensapesanan&delete=$p[id_laporan_pesanan]' onclick=\"return confirm('Anda yakin ingin hapus data ini?')\">X</a></center></td>";
			 }
			 echo "</tr>";
			 $no++;
		}
		if (isset($_GET[delete])){
			mysql_query("DELETE FROM rb_laporan_pesanan where id_laporan_pesanan='$_GET[delete]'");
			echo "<script>document.location='lap-lensa-pesanan.html';</script>";
		}
echo "	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='tambahlaplensapesanan'){
	if (isset($_POST[simpan])){
		 mysql_query("INSERT INTO rb_laporan_pesanan VALUES('',
		 													'".tgl_pesan($_POST[a])."',
		 													'$_POST[b]',
		 													'$_POST[c]',
		 													'$_POST[d]',
		 													'$_POST[e]',
															'$_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]',
															'".tgl_pesan($_POST[g])."',
															'$_POST[h]',
															'$_POST[i]')");
		echo "<script>document.location='lap-lensa-pesanan.html';</script>";
	}

echo "<div class='post_title' style='margin-left:20%;'><b>Tambahkan Laporan Lensa Pesanan.</b></div><hr><br/>
          <form method=POST action=''>
          <center><table width='60%'>
          <tr><td width='160px' class='td'><br>Tgl Pesan</td> <td class='td'><br/>:</td><td class='td'> <br><input type=text name='a' style='width:20%' id='tgl1'></td></tr>  
          <tr><td class='td'>No PO</td>   <td class='td'>:</td><td class='td'> <input type=text name='b' style='width:40%'></td></tr>
		  <tr><td class='td'>Distributor</td>   <td class='td'>:</td><td class='td'> <input type=text name='c' style='width:70%'></td></tr>
		  <tr><td class='td'>Nama Konsumen</td>   <td class='td'>:</td><td class='td'> <input type=text name='d' style='width:70%'></td></tr>
		  <tr><td class='td'>Nama Lensa</td>   <td class='td'>:</td><td class='td'> <select name='e' style='width:70%'>
		  																				<option value='' selected>- Pilih -</option>";
		  																				$nama = mysql_query("SELECT * FROM rb_ukuran");
		  																				while($n = mysql_fetch_array($nama)){
		  																					echo "<option value='$n[id_ukuran]'>$n[ukuran]</option>";
		  																				}
		  																			echo "</select></td></tr>
		  <tr><td class='td'>Ukuran</td>   <td class='td'>:</td><td class='td'>"; include "master/ukuran_pesanan.php"; echo "</td></tr>
		  <tr><td class='td'>Tgl Sampai</td>   <td class='td'>:</td><td class='td'> <input type=text name='g' style='width:20%' id='tgl3'></td></tr>
		  <tr><td class='td'>Memo</td>   <td class='td'>:</td><td class='td'> <input type=text name='h' style='width:50%'></td></tr>
		  <tr><td class='td'>Keterangan</td>   <td class='td'>:</td><td class='td'><textarea name='i' 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='simpan' class='button-reply' type=submit value=Simpan></td></tr>
          </table></center></form>";
}

elseif ($_GET[module]=='editlaplensapesanan'){
if (isset($_POST[update])){
	mysql_query("UPDATE rb_laporan_pesanan SET tgl_pesan = '".tgl_pesan($_POST[a])."',
											   no_po  = '$_POST[b]',
											   distributor = '$_POST[c]',
											   nama_konsumen = '$_POST[d]',
											   jenis_lensa = '$_POST[e]',
											   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]',
											   tgl_sampai = '".tgl_pesan($_POST[g])."',
											   extion = '$_POST[h]',
											   keterangan = '$_POST[i]' where id_laporan_pesanan='$_POST[id]'");
	echo "<script>document.location='lap-lensa-pesanan.html';</script>";
}

$edit=mysql_query("SELECT * FROM rb_laporan_pesanan WHERE id_laporan_pesanan='$_GET[id]'");
$p=mysql_fetch_array($edit);
echo "<div class='post_title' style='margin-left:20%;'><b>Edit Laporan Lensa Pesanan</b></div><hr><br/>
          <form method=POST action=''>
		  
          <center><table width='60%'>
          <input type=hidden name='id' value='$_GET[id]'>
          <tr><td width='160px' class='td'><br>Tgl Pesan</td> <td class='td'><br/>:</td><td class='td'> <br><input type=text name='a' style='width:20%' id='tgl1' value='".tgl_indo($p[tgl_pesan])."'></td></tr>  
          <tr><td class='td'>No PO</td>   <td class='td'>:</td><td class='td'> <input type=text name='b' style='width:40%' value='$p[no_po]'></td></tr>
		  <tr><td class='td'>Distributor</td>   <td class='td'>:</td><td class='td'> <input type=text name='c' style='width:70%' value='$p[distributor]'></td></tr>
		  <tr><td class='td'>Nama Konsumen</td>   <td class='td'>:</td><td class='td'> <input type=text name='d' style='width:70%' value='$p[nama_konsumen]'></td></tr>
		  <tr><td class='td'>Nama Lensa</td>   <td class='td'>:</td><td class='td'> <select name='e' style='width:70%'>";
		  																				$nama = mysql_query("SELECT * FROM rb_ukuran");
		  																				while($n = mysql_fetch_array($nama)){
		  																					if ($p[jenis_lensa]==$n[id_ukuran]){
		  																						echo "<option value='$n[id_ukuran]' selected>$n[ukuran]</option>";
		  																					}else{
		  																						echo "<option value='$n[id_ukuran]'>$n[ukuran]</option>";
		  																					}
		  																				}
		  																			echo "</select></td></tr>
		  <tr><td class='td'>Ukuran</td>   <td class='td'>:</td><td class='td'>"; include "master/ukuran_pesanan.php"; echo "</td></tr>
		  <tr><td class='td'>Tgl Sampai</td>   <td class='td'>:</td><td class='td'> <input type=text name='g' style='width:20%' id='tgl3' value='".tgl_indo($p[tgl_sampai])."'></td></tr>
		  <tr><td class='td'>Memo</td>   <td class='td'>:</td><td class='td'> <input type=text name='h' style='width:50%' value='$p[extion]'></td></tr>
		  <tr><td class='td'>Keterangan</td>   <td class='td'>:</td><td class='td'><textarea name='i' style='width:100%; height:60px;'>$p[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='update' class='button-reply' type=submit value=Update></td></tr>
          </table></center></form>"; 
}
?>