<?php
date_default_timezone_set("Asia/Jakarta");
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            User
            <small>Klinik</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Klinik</a></li>
            <li class="active">User</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <!-- SELECT2 EXAMPLE -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">User Klinik <a href="" data-toggle="modal" data-target="#tambahUser" class="btn btn-sm btn-info"><i class="fa fa-plus"></i> Tambah</a></h3>
                        <div class="box-tools pull-right">
                            <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                            <button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
                        </div>
                    </div><!-- /.box-header -->
                    <div class="box-body">
                        <small>
                            <!-- Custom Tabs -->
                            <div class="nav-tabs-custom">
                                
                                <div class="tab-content">
                                   
                                        <table class="table table-striped table-hover">
                                            <thead>
                                                <tr>
                                                    <th>No.</th>
                                                    <th>Nama</th>
                                                    <th>Username</th>
                                                    <th>Password</th>
                                                    <th>Level</th>
                                                    <th>Status</th>
                                                    <th>Status</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php 
                                                $no=1;
                                                foreach($klinik as $data):
                                                    $id = $data['id'];
                                                    ?>
                                                    <tr>
                                                        <td><?= $no++; ?>.</td>
                                                        <td><?= $data['nama']; ?></td>
                                                        <td><?= $data['username']; ?></td>
                                                        <td><?= $data['password']; ?></td>
                                                        <td>
                                                            <?php 
                                                            if($data['dept'] == 1){
                                                                echo "Dokter";
                                                            }else if($data['dept'] == 2){
                                                                echo "Apoteker";
                                                            }else if($data['dept'] == 3){
                                                                echo "Perawat";
                                                            }else{
                                                                echo "Admin";
                                                            }
                                                            ?>
                                                        </td>
                                                        <td>
                                                            <?php 
                                                            if($data['userstatus'] == 1){
                                                                echo "Aktif";
                                                            }else{
                                                                echo "Non-Aktif";
                                                            }
                                                            ?>
                                                        </td>
                                                        <td>
                                                            <a href="" data-toggle="modal" data-target="#edit<?=$data['id'];?>" class="btn btn-sm btn-success"><i class="fa fa-edit"></i> Edit</a> 
                                                            <?php 
                                                            if($data['dept'] == 13){
                                                                ?>
                                                                <a href="#" disabled class="btn btn-sm btn-danger"><i class="fa fa-trash"></i> Hapus</a>
                                                                <?php 
                                                            }else{
                                                                ?>
                                                                <a href="<?= base_url('user/hapus/'.$data['id']); ?>" onclick="return confirm('hapus ?');" class="btn btn-sm btn-danger"><i class="fa fa-trash"></i> Hapus</a>
                                                                <?php 
                                                            }
                                                            ?>
                                                        </td>
                                                    </tr>
                                                    <?php 
                                                endforeach;
                                                ?>
                                            </tbody>
                                        </table>

                                        
                                   
                                    
                                    
                                </div><!-- /.tab-content -->
                            </div><!-- nav-tabs-custom -->
                        </small>
                    </div><!-- /.box-body -->
                    <div class="box-footer">
                        <small>Daftar Pemeriksaan <?= date('d F Y'); ?> - @Klinik <?= date('Y'); ?></small>
                    </div>
                </div><!-- /.box -->
            </div>
        </div>

    </section><!-- /.content -->
</div><!-- /.content-wrapper -->

<!-- Modal -->
<div class="modal fade" id="tambahUser" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <form action="<?= base_url('user/prosesUser'); ?>" method="post">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Tambah User</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          <table class="table">
              <tr>
                  <td>Nama</td>
                  <td>
                      <input type="text" name="id" hidden value="<?= $countklinik['id']+1; ?>">
                      <input type="text" class="form-control" name="nama" required>
                  </td>
              </tr>
              <tr>
                  <td>Username</td>
                  <td>
                      <input type="text" class="form-control" name="username" required>
                  </td>
              </tr>
              <tr>
                  <td>Password</td>
                  <td>
                      <input type="text" class="form-control" name="password" required>
                  </td>
              </tr>
              <tr>
                  <td>Level</td>
                  <td>
                      <select required name="dept" class="form-control">
                        <option value="">- Pilih -</option>
                        <option value="1">Dokter</option>
                        <option value="2">Apoteker</option>
                        <option value="3">Perawat</option>
                      </select>
                  </td>
              </tr>
              <tr>
                  <td>Status</td>
                  <td>
                      <select required name="userstatus" class="form-control">
                        <option value="">- Pilih -</option>
                        <option value="1">Aktif</option>
                        <option value="0">Non-Aktif</option>
                      </select>
                  </td>
              </tr>
          </table>                                         
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary" >Simpan</button>
      </div>
    </div>
    </form>
  </div>
</div>

<?php 
foreach($klinik as $edit):
?>
<!-- Modal -->
<div class="modal fade" id="edit<?= $edit['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <form action="<?= base_url('user/updateUser/'.$edit['id']); ?>" method="post">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Tambah User</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
          <table class="table">
              <tr>
                  <td>Nama</td>
                  <td>
                      <input type="text" name="id" hidden value="<?= $edit['id']; ?>">
                      <input type="text" class="form-control" name="nama" value="<?= $edit['nama']; ?>" required>
                  </td>
              </tr>
              <tr>
                  <td>Username</td>
                  <td>
                      <input type="text" value="<?= $edit['username']; ?>" class="form-control" name="username" required>
                  </td>
              </tr>
              <tr>
                  <td>Password</td>
                  <td>
                      <input type="text" class="form-control" value="<?= $edit['password']; ?>" name="password" required>
                  </td>
              </tr>
              <tr>
                  <td>Level</td>
                  <td>
                      <select required name="dept" class="form-control">
                        <option value="">- Pilih -</option>
                        <?php 
                        if($edit['dept'] == 1){
                            ?>
                            <option selected value="1">Dokter</option>
                            <option value="2">Apoteker</option>
                            <option value="3">Perawat</option>
                            <option value="13">Admin</option>
                            <?php 
                        }else if($edit['dept'] == 2){
                            ?>
                            <option value="1">Dokter</option>
                            <option selected value="2">Apoteker</option>
                            <option value="3">Perawat</option>
                            <option value="13">Admin</option>
                            <?php 
                        }else if($edit['dept'] == 3){
                            ?>
                            <option value="1">Dokter</option>
                            <option value="2">Apoteker</option>
                            <option selected value="3">Perawat</option>
                            <option value="13">Admin</option>
                            <?php 
                        }else{
                            ?>
                            <option value="1">Dokter</option>
                            <option value="2">Apoteker</option>
                            <option value="3">Perawat</option>
                            <option selected value="13">Admin</option>
                            <?php 
                        }
                        ?>
                      </select>
                  </td>
              </tr>
              <tr>
                  <td>Status</td>
                  <td>
                      <select required name="userstatus" class="form-control">
                        <option value="">- Pilih -</option>
                        <?php 
                        if($edit['userstatus'] == 1){
                            ?>
                            <option value="1" selected>Aktif</option>
                            <option value="0">Non-Aktif</option>
                            <?php 
                        }else{
                            ?>
                            <option value="1">Aktif</option>
                            <option value="0" selected>Non-Aktif</option>
                            <?php 
                        }
                        ?>
                      </select>
                  </td>
              </tr>
          </table>                                         
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary" >Update</button>
      </div>
    </div>
    </form>
  </div>
</div>
<?php 
endforeach;
?>