<?php
session_name("AUTHENUSER");
session_start();
$USERNAME = $_SESSION['SES_USERNAME'];
if(!session_name("AUTHENUSER"))
	{
?>
						<script language="javascript">
						 alert("Waktu Login telah habis.Silahkan Login Kembali");
						document.location="index.php";
						</script>
<?php
	}
if(!$USERNAME)
	{
?>
						<script language="javascript">
						 alert("Harap Login Dahulu.");
						document.location="index.php";
						</script>
<?php
	}
	?>
	<?php 
	include "common/config.php";
	include "include/head.php";

	$act  = $_REQUEST['act'];
	$id_supplier  = $_REQUEST['id_supplier'];
	$sql = mysql_fetch_array(mysql_query("select * from tbl_supplier where id_supplier ='$id_supplier'"));
	$kode_supplier = $sql['kode_supplier'];
	$nama_supplier = $sql['nama_supplier'];
	$alamat_supplier = $sql['alamat_supplier'];
	$id_kota 	 = $sql['id_kota'];
	$kodepos 	 = $sql['kodepos'];
	$telepon 	 = $sql['telepon'];
	$telepon 	 = $sql['telepon'];
	$handphone 	 = $sql['handphone'];
	$email 	 = $sql['email'];
	$nomorrekening= $sql['nomorrekening'];
	$namabank= $sql['namabank'];
	$alamatbank= $sql['alamatbank'];
	
	if($act == 1)
	{
		$id_supplier  = $_REQUEST['id_supplier'];
		$nama  = $_REQUEST['nama'];
		$alamat  = $_REQUEST['alamat'];
		$kota  = $_REQUEST['kota'];
		$kodepos  = $_REQUEST['kodepos'];
		$telepon  = $_REQUEST['telepon'];
		$handphone  = $_REQUEST['handphone'];
		$email  = $_REQUEST['email'];
		$rekening  = $_REQUEST['rekening'];
		$namabank  = $_REQUEST['namabank'];
		$alamatbank  = $_REQUEST['alamatbank'];
		if($nama ==  "")
		{
		?>
				<script language="javascript">
                alert("Input Nama Supplier");
                document.location="edit_supplier.php?id_supplier=<?php echo $id_supplier; ?>";
                </script>
		<?php	
		}
		else
		{
			$insert = mysql_query("update tbl_supplier set nama_supplier='$nama',alamat_supplier='$alamat',id_kota='$kota', kodepos='$kodepos',telepon='$telepon', 	handphone='$handphone',email='$email',nomorrekening='$rekening', 	namabank='$namabank',
			alamatbank='$alamatbank',user_update ='$USERNAME' where id_supplier='$id_supplier'");
			if($insert)
			{
				?>
				<script language="javascript">
                alert("Edit Supplier Success");
                document.location="edit_supplier.php?id_supplier=<?php echo $id_supplier; ?>";
                </script>
				<?php
			}
			else
			{
				?>
				<script language="javascript">
                alert("Edit Supplier Failed");
                document.location="edit_supplier.php?id_supplier=<?php echo $id_supplier; ?>";
                </script>
				<?php	
			}
		}
	}
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-th"></i> Edit Supplier</h1>
</div>

<!--<ol class="breadcrumb">
  <li><a href="#">Home</a></li>
  <li><a href="#">Bread</a></li>
  <li><a href="#">Crumbs</a></li>
  <li class="active">Example</li>
</ol>-->
          <div class="main-content">
            <div class="row">
                <div class="widget">
                  <div class="widget-content-white glossed">
                    <div class="padded">
                      <form method="post" action="edit_supplier.php?act=1&id_supplier=<?php echo $id_supplier; ?>" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label">Kode Supplier</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="kode" id="kode" value="<?php echo $kode_supplier; ?>"  readonly="readonly">
                          </div>
                          </div>
                           <div class="form-group">
                          <label class="col-md-4 control-label">Nama Supplier</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="nama" id="nama" value="<?php echo $nama_supplier; ?>">
                          </div>
                        </div>
                         <div class="form-group">
                          <label class="col-md-4 control-label">Alamat Supplier</label>
                          <div class="col-md-8">
                            <textarea cols="80" rows="5" name="alamat" id="alamat" class="form-control"><?php echo $alamat_supplier; ?></textarea>
                          </div>
                        </div>
                            <div class="form-group">
                          <label class="col-md-4 control-label">Kota</label>
                          <div class="col-md-8">
                            <select class="form-control"  name="kota" id="kota">
                             <?php
                                              $sql3 = "select * from tbl_kota where status_kota=1 order by nama_kota";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                           <option <?php if($fetch3['id_kota']==$id_kota) { ?> selected="selected" <?php } ?> value="<?php echo $fetch3['id_kota']; ?>"><?php echo $fetch3['nama_kota']; ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                          </div>
                        </div>
                        
                         <div class="form-group">
                          <label class="col-md-4 control-label">Kode Pos</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="kodepos" id="kodepos" value="<?php echo $kodepos; ?>">
                          </div>
                        </div>
                         <div class="form-group">
                          <label class="col-md-4 control-label">Telepon</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="telepon" id="telepon" value="<?php echo $telepon; ?>">
                          </div>
                        </div>
                         <div class="form-group">
                          <label class="col-md-4 control-label">Handphone</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="handphone" id="handphone" value="<?php echo $handphone; ?>">
                          </div>
                        </div>
                         <div class="form-group">
                          <label class="col-md-4 control-label">Email</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="email" id="email" value="<?php echo $email; ?>">
                          </div>
                        </div>
                          <div class="form-group">
                          <label class="col-md-4 control-label">Nomor Rekening</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="rekening" id="rekening" value="<?php echo $nomorrekening; ?>">
                          </div>
                        </div>
                          <div class="form-group">
                          <label class="col-md-4 control-label">Nama Bank</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="namabank" id="namabank"  value="<?php echo $namabank; ?>">
                          </div>
                        </div>
                    <div class="form-group">
                          <label class="col-md-4 control-label">Alamat Bank</label>
                          <div class="col-md-8">
                            <textarea cols="80" rows="5" name="alamatbank" id="alamatbank" class="form-control" ><?php echo $alamatbank; ?></textarea>
                          </div>
                        </div>
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="submit" class="btn btn-default">Submit</button>
                            <button type="reset" class="btn btn-default">Reset</button>
                          </div>
                        </div>
                      </form>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

<?php include "include/foot.php"; ?>
<script src='assets/js/for_pages/dashboard.js'></script>
</body>

</html>