<?php
include("../library/inc.connection.php");
include_once "library/inc.library.php";
include_once "library/inc.sesadmin.php";
include_once "library/inc.dataadmin.php";
# Opsi Level Login

if($_GET) {
  if(isset($_POST['btnSave'])){

    # Baca Variabel Form
  	$txtKode  = $_POST['txtKode'];
    $txtKode  = str_replace("'","&acute;",$txtKode);
  	$txtMapel  = $_POST['txtMapel'];
    $txtMapel  = str_replace("'","&acute;",$txtMapel);
	$txtnmlokal  = $_POST['txtnmlokal'];
    $txtnmlokal  = str_replace("'","&acute;",$txtnmlokal);
    $txtKelompok  = $_POST['txtKelompok'];
    $txtKelompok  = str_replace("'","&acute;",$txtKelompok);
    $txtSemester  = $_POST['txtSemester'];
    $txtSemester  = str_replace("'","&acute;",$txtSemester);
    $txtJurusan  = $_POST['txtJurusan'];
    $txtJurusan  = str_replace("'","&acute;",$txtJurusan);
	 $txtNoUrut  = $_POST['txtNoUrut'];
    $txtNoUrut  = str_replace("'","&acute;",$txtNoUrut);
	 $txtringkas  = $_POST['txtringkas'];
    $txtringkas  = str_replace("'","&acute;",$txtringkas);

    $sqlSave="UPDATE tabel_mapel SET nm_mapel='$txtMapel', kelompok='S', nm_lokal='$txtMapel',nm_ringkas='$txtringkas'
      WHERE mata_pelajaran_id='$txtKode'";
     $qrySave=pg_query($sqlSave);
      if($qrySave){
        echo "<script>alert('Data Mata Pelajaran Berhasil Diedit ');
        location.replace('?page=Data-Mapel-Suplemen');</script>";
      }
      else {echo "<script>alert('Gagal mengubah Data Mata Pelajaran');
        location.replace('?page=Data-Mapel-Suplemen');</script>";
	   }

	     
 }}

  # TAMPILKAN DATA LOGIN UNTUK DIEDIT 
  $KodeEdit= isset($_GET['Kode']) ?  $_GET['Kode'] : $_POST['txtKode']; 
  $sqlShow = "SELECT * FROM tabel_mapel 
  WHERE mata_pelajaran_id='$KodeEdit' AND kelompok in('S','D')";
  $qryShow = pg_query($sqlShow)  or die ("Query ambil data mata pelajaran salah : ".pg_last_error());
  $dataShow = pg_fetch_array($qryShow);
  $cekKode =  $dataShow['mata_pelajaran_id'];
  if($cekKode){
  
  # MASUKKAN DATA KE VARIABEL nm_sekolah  alamat  telepon fax pos logo
  $dataKode = isset($dataShow['mata_pelajaran_id']) ?  $dataShow['mata_pelajaran_id'] : $_POST['txtKode'];
  $dataMapel = isset($dataShow['nm_mapel']) ?  $dataShow['nm_mapel'] : $_POST['txtMapel'];
  $dataringkas = isset($dataShow['nm_ringkas']) ?  $dataShow['nm_ringkas'] : $_POST['txtringkas'];
 
  ?>
 
  <div class="col-xs-12">
<!-- Standar Tabel awal -->
		<div class="box table-responsive">
            <div class="box-header bg-navy">
              <h3 class="box-title"><li class='glyphicon glyphicon-pencil'></li> &nbsp;&nbsp; Edit Data Mata Pelajaran</h3>
			  <div class="box-tools pull-right">
			  <a href='?page=Data-Mapel-Suplemen' target='_self' alt='Tambah Guru' class="btn btn-warning btn-sm"><li class="glyphicon glyphicon-eject"></li> Batal Edit</a>   
            </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
<form action="?page=Mapel-Suplemen-Edit" method="post" name="frmadd" ENCTYPE="multipart/form-data">
<table class="table">
<tr>
    <td width="15%"><b>Kode Mapel</b></td>
    <td width="1%" align="center"><b>:</b></td>
    <td width="84%"><input class="form-control" type='text' name ='txtKode' value="<?php echo $dataKode; ?>" readonly></td>
</tr>

 <tr>
    <td><b>Nama Mapel</b></td>
    <td align="center"><b>:</b></td>
    <td><input class="form-control" type='text' name ='txtMapel' value="<?php echo $dataMapel; ?>">
    <td>
   </tr>

  <tr>
    <td><b>Nama Ringkas (Nama Singkatan)</b></td>
    <td align="center"><b>:</b></td>
    <td><input class="form-control" type='text' name ='txtringkas' value="<?php echo $dataringkas; ?>">
    <td>
   </tr>
 

  
  <?php } ?>
 <tr class="bg-info">
 <td colspan="3">
  <div class="box-tools pull-right">  
            <input class="btn btn-success" type='submit' name="btnSave" value='SIMPAN' onclick="jalankanload()">
			</div>
  
  </td>
</tr> 
</table>
</form>
</div><div id="loading" align="center"></div>
          </div>
<!-- Standar Tabel akhir -->
</div>


