<?php  
// fungsi untuk pengecekan tampilan form
// jika form add data yang dipilih
if ($_GET['form']=='add') { ?> 
  <!-- tampilan form add data -->
	<!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      <i class="fa fa-edit icon-title"></i> Tambah Lokasi
    </h1>
  </section>

  <!-- Main content -->
  <section class="content">
    <div class="row">
      <div class="col-md-12">
        <div class="box box-primary">
          <!-- form start -->
          <form role="form" class="form-horizontal" action="modules/lokasi/proses.php?act=insert" method="POST">
            <div class="box-body">
    

              <div class="form-group">
                <label class="col-sm-2 control-label">Lokasi</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="nama" autocomplete="off" required>
                </div>
              </div>
			  
			   <div class="form-group">
                <label class="col-sm-2 control-label">Sektor</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="sektor" data-placeholder="-- Pilih --" autocomplete="off" required>
					 
                    <?php
						
						$query = mysqli_query($mysqli, "SELECT * FROM is_sektor where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data = mysqli_fetch_assoc($query)) { 
							echo"<option value='$data[id]'>$data[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Kolekte Sektor</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="kolsektor" autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Kolekte Sektor</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kaskolsektor" data-placeholder="-- Pilih --" autocomplete="off" required>
					 
                    <?php
						
						$query = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data = mysqli_fetch_assoc($query)) { 
							echo"<option value='$data[id]'>$data[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Kolekte Runggun</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="kolrunggun" autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Kolekte Runggun</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kaskolrunggun" data-placeholder="-- Pilih --" autocomplete="off" required>
					 
                    <?php
						
						$query = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data = mysqli_fetch_assoc($query)) { 
							echo"<option value='$data[id]'>$data[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Kolekte Sinode</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="kolsinode" autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Kolekte Sinode</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kaskolsinode" data-placeholder="-- Pilih --" autocomplete="off" required>
					 
                    <?php
						
						$query = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data = mysqli_fetch_assoc($query)) { 
							echo"<option value='$data[id]'>$data[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Perpuluhen Sektor</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="psektor" autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Perpuluhen Sektor</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kaspersektor" data-placeholder="-- Pilih --" autocomplete="off" required>
					 
                    <?php
						
						$query = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data = mysqli_fetch_assoc($query)) { 
							echo"<option value='$data[id]'>$data[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Perpuluhen Runggun</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="prunggun" autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Perpuluhen Runggun</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kasperrunggun" data-placeholder="-- Pilih --" autocomplete="off" required>
					 
                    <?php
						
						$query = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data = mysqli_fetch_assoc($query)) { 
							echo"<option value='$data[id]'>$data[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Perpuluhen Sinode</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="psinode" autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Perpuluhen Sinode</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kaspersinode" data-placeholder="-- Pilih --" autocomplete="off" required>
					 
                    <?php
						
						$query = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data = mysqli_fetch_assoc($query)) { 
							echo"<option value='$data[id]'>$data[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>


            </div><!-- /.box body -->

            <div class="box-footer">
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                  <input type="submit" class="btn btn-primary btn-submit" name="simpan" value="Simpan">
                  <a href="?module=lokasi" class="btn btn-default btn-reset">Batal</a>
                </div>
              </div>
            </div><!-- /.box footer -->
          </form>
        </div><!-- /.box -->
      </div><!--/.col -->
    </div>   <!-- /.row -->
  </section><!-- /.content -->
<?php
}
// jika form edit data yang dipilih
// isset : cek data ada / tidak
elseif ($_GET['form']=='edit') { 
  if (isset($_GET['id'])) {
      // fungsi query untuk menampilkan data dari tabel obat
      $query = mysqli_query($mysqli, "SELECT *
											,(select nama from is_sektor where id = is_lokasi.sektor) as namasektor 
											,(select nama from kas where id = is_lokasi.kaskolsektor) as namakaskolsektor
											,(select nama from kas where id = is_lokasi.kaskolrunggun) as namakaskolrunggun
											,(select nama from kas where id = is_lokasi.kaskolsinode) as namakaskolsinode
											,(select nama from kas where id = is_lokasi.kaspersektor) as namakaspersektor
											,(select nama from kas where id = is_lokasi.kasperrunggun) as namakasperrunggun
											,(select nama from kas where id = is_lokasi.kaspersinode) as namakaspersinode
	  
											FROM is_lokasi WHERE id='$_GET[id]'") 
                                      or die('Ada kesalahan pada query tampil : '.mysqli_error($mysqli));
      $data  = mysqli_fetch_assoc($query);
    }
?>
  <!-- tampilan form edit data -->
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      <i class="fa fa-edit icon-title"></i> Edit Lokasi
    </h1>
  </section>

  <!-- Main content -->
  <section class="content">
    <div class="row">
      <div class="col-md-12">
        <div class="box box-primary">
          <!-- form start -->
          <form role="form" class="form-horizontal" action="modules/lokasi/proses.php?act=update" method="POST">
            <div class="box-body">
              <input type="text" class="form-control" style="display:none;" name="id" value="<?php echo $data['id']; ?>" required>
              <div class="form-group">
                <label class="col-sm-2 control-label">Nama</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control" name="nama" value="<?php echo $data['nama']; ?>" required>
                </div>
              </div>
			  
			  
			    <div class="form-group">
                <label class="col-sm-2 control-label">Sektor</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="sektor" data-placeholder="-- Pilih --" autocomplete="off" required>
					 <option value="<?php echo $data['sektor']; ?>"><?php echo $data['namasektor']; ?></option>
                    <?php
						
						$query2 = mysqli_query($mysqli, "SELECT * FROM is_sektor where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data2 = mysqli_fetch_assoc($query2)) { 
							echo"<option value='$data2[id]'>$data2[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Kolekte Sektor</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="kolsektor" value="<?php echo $data['kolsektor']; ?>"  autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Kolekte Sektor</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kaskolsektor" data-placeholder="-- Pilih --" autocomplete="off" required>
					 <option value="<?php echo $data['kaskolsektor']; ?>"><?php echo $data['namakaskolsektor']; ?></option>
                    <?php
						
						$query2 = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data2 = mysqli_fetch_assoc($query2)) { 
							echo"<option value='$data2[id]'>$data2[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Kolekte Runggun</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="kolrunggun" value="<?php echo $data['kolrunggun']; ?>"  autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Kolekte Runggun</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kaskolrunggun" data-placeholder="-- Pilih --" autocomplete="off" required>
					 <option value="<?php echo $data['kaskolrunggun']; ?>"><?php echo $data['namakaskolrunggun']; ?></option>
                    <?php
						
						$query2 = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data2 = mysqli_fetch_assoc($query2)) { 
							echo"<option value='$data2[id]'>$data2[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Kolekte Sinode</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="kolsinode" value="<?php echo $data['kolsinode']; ?>"  autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Kolekte Sinode</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kaskolsinode" data-placeholder="-- Pilih --" autocomplete="off" required>
					 <option value="<?php echo $data['kaskolsinode']; ?>"><?php echo $data['namakaskolsinode']; ?></option>
                    <?php
						
						$query2 = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data2 = mysqli_fetch_assoc($query2)) { 
							echo"<option value='$data2[id]'>$data2[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Perpuluhen Sektor</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="psektor"  value="<?php echo $data['psektor']; ?>" autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Perpuluhen Sektor</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kaspersektor" data-placeholder="-- Pilih --" autocomplete="off" required>
					 <option value="<?php echo $data['kaspersektor']; ?>"><?php echo $data['namakaspersektor']; ?></option>
                    <?php
						
						$query2 = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data2 = mysqli_fetch_assoc($query2)) { 
							echo"<option value='$data2[id]'>$data2[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Perpuluhen Runggun</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="prunggun"  value="<?php echo $data['prunggun']; ?>" autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Perpuluhen Runggun</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kasperrunggun" data-placeholder="-- Pilih --" autocomplete="off" required>
					 <option value="<?php echo $data['kasperrunggun']; ?>"><?php echo $data['namakasperrunggun']; ?></option>
                    <?php
						
						$query2 = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data2 = mysqli_fetch_assoc($query2)) { 
							echo"<option value='$data2[id]'>$data2[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  <hr>

			<div class="form-group">
                <label class="col-sm-2 control-label">Persen Perpuluhen Sinode</label>
                <div class="col-sm-5">
                  <input type="number" class="form-control" name="psinode" value="<?php echo $data['psinode']; ?>" autocomplete="off" required>
                </div>
              </div>
			
			<div class="form-group">
                <label class="col-sm-2 control-label">Kas Perpuluhen Sinode</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kaspersinode" data-placeholder="-- Pilih --" autocomplete="off" required>
					 <option value="<?php echo $data['kaspersinode']; ?>"><?php echo $data['namakaspersinode']; ?></option>
                    <?php
						
						$query2 = mysqli_query($mysqli, "SELECT * FROM kas where status='Y' ORDER BY nama asc")
                                            or die('Ada kesalahan pada query tampil: '.mysqli_error($mysqli));

						// tampilkan data
						while ($data2 = mysqli_fetch_assoc($query2)) { 
							echo"<option value='$data2[id]'>$data2[nama]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  
			  
			  
		
			  


            </div><!-- /.box body -->

            <div class="box-footer">
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                  <input type="submit" class="btn btn-primary btn-submit" name="simpan" value="Simpan">
                  <a href="?module=sektor" class="btn btn-default btn-reset">Batal</a>
                </div>
              </div>
            </div><!-- /.box footer -->
          </form>
        </div><!-- /.box -->
      </div><!--/.col -->
    </div>   <!-- /.row -->
  </section><!-- /.content -->
<?php
}
?>