<?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> Input Laporan Harian
    </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/lap-harian/proses.php?act=insert" method="POST" enctype="multipart/form-data">
            <div class="box-body">
              
              <div class="form-group">
                <label class="col-sm-2 control-label">Tanggal</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control date-picker" data-date-format="dd-mm-yyyy" name="tanggal" autocomplete="off" value="<?php echo date("d-m-Y"); ?>" required>
                </div>
              </div>

              <div class="form-group">
                <label class="col-sm-2 control-label">Kegiatan</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kegiatan" data-placeholder="-- Pilih --" autocomplete="off" required>
					<option value=''></option>
					<?php
						$user = $_SESSION['id_user'];
						$query2 = mysqli_query($mysqli, "SELECT * FROM is_kegiatan where status='Y' and created_user = '$user' ORDER BY kegiatan 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[kegiatan]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  <div class="form-group">
                <label class="col-sm-2 control-label">Analisa Kegiatan</label>
                <div class="col-sm-5">
                  <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-file-text icon-title"></i></span>
                    <input type="text" class="form-control" name="analisa" autocomplete="off"  required>
                  </div>
                </div>
              </div>
			  
			  <div class="form-group">
                <label class="col-sm-2 control-label">Status</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="selesai" data-placeholder="-- Pilih --" autocomplete="off" required>
                    <option value=""></option>
                    <option value="Y">Selesai</option>
                    <option value="N">On Process</option>
                  </select>
                </div>
              </div>

              <div class="form-group">
                <label class="col-sm-2 control-label">Keterangan</label>
                <div class="col-sm-5">
                  <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-file-text icon-title"></i></span>
                    <input type="text" class="form-control" name="keterangan" autocomplete="off"  required>
                  </div>
                </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=lap_harian" 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 kegiatan from is_kegiatan where id = t_harian.kegiatan)as nama_kegiatan FROM t_harian WHERE id='$_GET[id]'") 
                                      or die('Ada kesalahan pada query tampil Data : '.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 Laporan Harian
    </h1>
    <ol class="breadcrumb">
      <li><a href="?module=beranda"><i class="fa fa-home"></i> Beranda </a></li>
      <li><a href="?module=obat"> Laporan Harian </a></li>
      <li class="active"> Edit </li>
    </ol>
  </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/lap-harian/proses.php?act=update" method="POST" enctype="multipart/form-data">
            <div class="box-body">

                  <input type="text" class="form-control" style="display:none" name="id" value="<?php echo $data['id']; ?>" readonly required>
				  
				<div class="form-group">
                <label class="col-sm-2 control-label">Tanggal</label>
                <div class="col-sm-5">
                  <input type="text" class="form-control date-picker" data-date-format="dd-mm-yyyy" name="tanggal" autocomplete="off" value="<?php echo date("d-m-Y",strtotime($data['billdate'])); ?>" required>
                </div>
              </div>

		  
			  
			  <div class="form-group">
                <label class="col-sm-2 control-label">Kegiatan</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="kegiatan" data-placeholder="-- Pilih --" autocomplete="off" required>
                    <option value="<?php echo $data['kegiatan']; ?>"><?php echo $data['nama_kegiatan']; ?></option>
					<?php
						$user = $_SESSION['id_user'];
						$query2 = mysqli_query($mysqli, "SELECT * FROM is_kegiatan where status='Y' and created_user = '$user' ORDER BY kegiatan 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[kegiatan]</option>";
						}
						
						?>
                  </select>
                </div>
              </div>
			  
			  <div class="form-group">
                <label class="col-sm-2 control-label">Analisa Kegiatan</label>
                <div class="col-sm-5">
                  <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-file-text icon-title"></i></span>
                    <input type="text" class="form-control" name="analisa" value="<?php echo $data['analisa']; ?>"  autocomplete="off"  required>
                  </div>
                </div>
              </div>

              
			  
			   <div class="form-group">
                <label class="col-sm-2 control-label">Keterangan</label>
                <div class="col-sm-5">
                  <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-file-text icon-title"></i></span>
                    <input type="text" class="form-control" name="keterangan" value="<?php echo $data['keterangan']; ?>"  autocomplete="off"  required>
                  </div>
                </div>
              </div>
			  
			  <div class="form-group">
                <label class="col-sm-2 control-label">Status</label>
                <div class="col-sm-5">
                  <select class="chosen-select" name="selesai" data-placeholder="-- Pilih --" autocomplete="off" required>
                    <option value="<?php echo $data['selesai']; ?>"><?php 
							if($data['selesai'] =="Y"){
								echo"Selesai";
							}else{
								echo"On Process";
							}
					?></option>
					<?php
						if($data['selesai'] == "Y"){
							echo"<option value='N'>On Process</option>";
						}else{
							echo"<option value='Y'>Selesai</option>";
						}
					?>
                  </select>
                </div>
              </div>
			  
			  <div class="form-group">
                <label class="col-sm-2 control-label">Image</label>
                <div class="col-sm-5">
                  <input type="file" name="foto">
                  <br/>
                <?php  
                if ($data['img']=="") { ?>
                  <img style="border:1px solid #eaeaea;border-radius:5px;" src="images/user/task-default.png" width="128">
                <?php
                }
                else { ?>
                  <img style="border:1px solid #eaeaea;border-radius:5px;" data-toggle='modal' data-target='#myModal' src="images/user/<?php echo $data['img']; ?>" width="128">
                <?php
                }
                ?>
                </div>
              </div>

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

            <div class="box-footer">
              <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
					<?php
						if($data['val'] !="Y"){
							echo" <input type='submit' class='btn btn-primary btn-submit' name='simpan' value='Simpan'>";
						}
					?>
				
                 
                  <a href="?module=lap_harian" class="btn btn-default btn-reset">Batal</a>
                </div>
              </div>
            </div><!-- /.box footer -->
          </form>
        </div><!-- /.box -->
		<?php
			echo"							
				<div id='myModal' class='modal fade' tabindex='-1' role='dialog'>
				  <div class='modal-dialog'>
					<div class='modal-content'>
						<div class='modal-body'>
							<img src='images/user/$data[img]' class='img-responsive'>
						</div>
					</div>
				  </div>
				</div>";
		?>
      </div><!--/.col -->
    </div>   <!-- /.row -->
  </section><!-- /.content -->
<?php
}
?>