<?php
$user = new viewuser();
$level = new viewlevel();
$lab = new viewlab();
switch($_GET[act]){
default:
    $u = $user->listuser('admin');
    echo"
        <div class='content-wrapper'>
            <!-- Content Header (Page header) -->
            <section class='content-header'>
                <h1>
                    Data Petugas
                </h1><br />
                <a class='btn btn-app' href='index.php?module=admin&act=tambah'>
                    <i class='fa fa-plus'></i> Tambah
                </a>
            </section>

            <!-- Main content -->
            <section class='content'>
              <div class='row'>
                <div class='col-xs-12'>
                  <div class='box'>
                    <div class='box-body'>
                      <table id='example2' class='table table-bordered table-hover'>
                        <thead>
                          <tr>
                            <th>Nama</th>
                            <th>Nip</th>
                            <th>Bagian</th>
                            <th>Status</th>
                            <th></th>
                          </tr>
                        </thead>
                        <tbody>";
                            while($i<count($u)){
                                echo"
                                    <tr>
                                        <td>".$u[$i][nama]."</td>
                                        <td>".$u[$i][nip]."</td>
                                        <td>".$u[$i][bagian]."</td>";
                                        if ($u[$i][blokir]=='N'){
                                            echo"<td><i class='fa fa-check fa-fw'></i> Active</td>";
                                        } else {
                                            echo"<td><i class='fa fa-ban fa-fw'></i> Ban</td>";
                                        }
                                        echo "
                                        <td>
                                            <div class='hidden-sm hidden-xs action-buttons'>
                                                <a class='blue' href='index.php?module=admin&act=edit&id=".$u[$i][id_user]."'>
                                                    <i class='ace-icon fa fa-search-plus bigger-130'></i>
                                                </a>

                                                <a class='red' href='view/view/modul/mod_admin/aksi_admin.php?aksi=delete&id=".$u[$i][id_user]."'>
                                                    <i class='ace-icon fa fa-trash-o bigger-130'></i>
                                                </a>
                                            </div>
                                        </td>
                                    </tr>";
                                $i++;
                            }
                        echo" 
                        </tbody>
                        <tfoot>
                          <tr>
                            <th>Nama</th>
                            <th>Nip</th>
                            <th>Bagian</th>
                            <th>Status</th>
                            <th></th>
                          </tr>
                        </tfoot>
                      </table>
                    </div><!-- /.box-body -->
                  </div><!-- /.box -->
                </div><!-- /.col -->
              </div><!-- /.row -->
            </section><!-- /.content -->
          </div><!-- /.content-wrapper -->";
        break;
        
    case "tambah":
        echo"
        <div class='content-wrapper'>
            <!-- Content Header (Page header) -->
            <section class='content-header'>
                <h1>
                    Tambah Petugas
                </h1><br />
                <a class='btn btn-app' href='index.php?module=admin'>
                    <i class='fa fa-rotate-left'></i> Kembali
                </a>
            </section>

            <!-- Main content -->
            <section class='content'>
              <div class='row'>
                <!-- left column -->
                <div class='col-md-9'>
                  <!-- general form elements -->
                  <div class='box box-primary'>
                    <div class='box-header with-border'>
                      <h3 class='box-title'>Form</h3>
                    </div><!-- /.box-header -->
                    <!-- form start -->
                    <form role='form' action='view/view/modul/mod_admin/aksi_admin.php?aksi=tambah' method='post' enctype='multipart/form-data'>
                      <div class='box-body'>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>Username</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='Username' name='username'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputPassword1'>Password</label>
                          <input type='password' class='form-control' id='exampleInputPassword1' placeholder='Password' name='password'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputPassword1'>Ulangi Password</label>
                          <input type='password' class='form-control' id='exampleInputPassword1' placeholder='Ulangi Password' name='rpassword'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>Nama</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='Nama UPI' name='nama'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>NIP</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='NIP' name='nip'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>Alamat</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='Alamat' name='alamat_admin'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>Email</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='Email' name='email_admin'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>Telpon</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='Telpon' name='telpon_admin'>
                        </div>
                        <div class='form-group'>
                            <label for='exampleInputEmail1'> Laboratorium </label>
                            <select class='form-control' name='lab'>
                            <option value='0'>Umum</option>";
                                $lb = $lab->listlab();
                                            
                                while($i<count($lb)){
                                        echo"<option value='".$lb[$i][id_lab]."'>".$lb[$i][nama]."</option>"; 
                                    $i++;
                                }
                                unset($i);
                            echo"
                            </select>
                        </div>
                        <div class='form-group'>
                            <label for='exampleInputEmail1'> Level </label>
                            <select class='form-control' name='level'>";
                                $l = $level->listlevel();
                                            
                                while($i<count($l)){
                                        echo"<option value='".$l[$i][id_level]."'>".$l[$i][level]."</option>";
                                    $i++;
                                }
                                unset($i);
                            echo"
                            </select>
                        </div>
                        <div class='form-group'>
                            <label for='exampleInputEmail1'> Blokir </label>
                            <select class='form-control' name='blokir'>
                                <option value='Y'>Blokir</option>
                                <option value='N'>Active</option>
                            </select>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputFile'>Photo</label>
                          <input type='file' id='exampleInputFile' name='gambar'>
                          <p class='help-block'>Example block-level help text here.</p>
                        </div>
                      </div><!-- /.box-body -->

                      <div class='box-footer'>
                        <button type='submit' class='btn btn-primary'>Submit</button>
                      </div>
                    </form>
                  </div><!-- /.box -->
                </div><!--/.col (left) -->
                <!-- right column -->
                <div class='col-md-3'>
                    <div class='box box-primary'>
                        <div class='box-body box-profile'>";

                            if(empty($u[logo])){
                                echo"<img class='profile-user-img img-responsive img-circle' src='file/profile/default_user.png' alt='User profile picture'>";
                            }else{
                                echo"<img class='profile-user-img img-responsive img-circle' src='file/profile/$u[logo]' alt='User profile picture'>";
                            }

                          echo"        
                          <h3 class='profile-username text-center'>".$u[nama]."</h3>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!--/.col (right) -->
              </div>   <!-- /.row -->
            </section><!-- /.content -->
          </div><!-- /.content-wrapper -->
        ";  
    break;    

    case "edit":
        $user->id = $_GET[id];
        $u = $user->user();
        
        if($u[blokir]=='Y'){
            $blokir = 'Blokir';
        }elseif($u[blokir]=='N'){
            $blokir = 'Active';
        }
        echo"
        <div class='content-wrapper'>
            <!-- Content Header (Page header) -->
            <section class='content-header'>
                <h1>
                    Tambah Admin
                </h1><br />
                <a class='btn btn-app' href='index.php?module=admin'>
                    <i class='fa fa-rotate-left'></i> Kembali
                </a>
            </section>

            <!-- Main content -->
            <section class='content'>
              <div class='row'>
                <!-- left column -->
                <div class='col-md-9'>
                  <!-- general form elements -->
                  <div class='box box-primary'>
                    <div class='box-header with-border'>
                      <h3 class='box-title'>Form</h3>
                    </div><!-- /.box-header -->
                    <!-- form start -->
                    <form role='form' action='view/view/modul/mod_admin/aksi_admin.php?aksi=edit' method='post' enctype='multipart/form-data'>
                      <input type=hidden name='id' value='".$u[id_user]."'>
                      <input type=hidden name='username' value='".$u[username]."'>
                      <input type=hidden name='logo' value='".$u[logo]."'>    
                      <div class='box-body'>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>Username</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='Username' value='".$u[username]."' disabled>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputPassword1'>Password</label>
                          <input type='password' class='form-control' id='exampleInputPassword1' placeholder='Password' name='password'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputPassword1'>Ulangi Password</label>
                          <input type='password' class='form-control' id='exampleInputPassword1' placeholder='Ulangi Password' name='rpassword'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>Nama</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='Nama UPI' value='".$u[nama]."' name='nama'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>NIP</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='NIP' value='".$u[nip]."' name='nip'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>Alamat</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='Alamat' value='".$u[alamat_admin]."' name='alamat_admin'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>Email</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='Email' value='".$u[email_admin]."' name='email_admin'>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputEmail1'>Telpon</label>
                          <input type='text' class='form-control' id='exampleInputEmail1' placeholder='Telpon' value='".$u[telpon_admin]."' name='telpon_admin'>
                        </div>
                        <div class='form-group'>
                            <label for='exampleInputEmail1'> Laboratorium </label>
                            <select class='form-control' name='lab'>
                            <option value='umum'>umum</option>";
                                $lb = $lab->listlab();
                                            
                                while($i<count($lb)){
                                    if($lb[$i][id_lab]==$u[lab]){
                                        echo"<option selected='selected' value='".$lb[$i][id_lab]."'>".$lb[$i][nama]."</option>"; 
                                    }else{
                                        echo"<option value='".$lb[$i][id_lab]."'>".$lb[$i][nama]."</option>"; 
                                    }
                                    $i++;
                                }
                                unset($i);
                            echo"
                            </select>
                        </div>
                        <div class='form-group'>
                            <label for='exampleInputEmail1'> Level </label>
                            <select class='form-control' name='level'>";
                                $l = $level->listlevel();
                                            
                                while($i<count($l)){
                                    if($l[$i][id_level]==$u[id_level]){
                                        echo"<option selected='selected' value='".$l[$i][id_level]."'>".$l[$i][level]."</option>"; 
                                    }else{
                                        echo"<option value='".$l[$i][id_level]."'>".$l[$i][level]."</option>"; 
                                    }
                                    $i++;
                                }
                                unset($i);
                            echo"
                            </select>
                        </div>
                        <div class='form-group'>
                            <label for='exampleInputEmail1'> Blokir </label>
                            <select class='form-control' name='blokir'>
                                <option value='".$u[blokir]."'>".$blokir."</option>
                                <option value='Y'>Blokir</option>
                                <option value='N'>Active</option>
                            </select>
                        </div>
                        <div class='form-group'>
                          <label for='exampleInputFile'>Photo</label>
                          <input type='file' id='exampleInputFile' name='gambar'>
                          <p class='help-block'>Example block-level help text here.</p>
                        </div>
                      </div><!-- /.box-body -->

                      <div class='box-footer'>
                        <button type='submit' class='btn btn-primary'>Submit</button>
                      </div>
                    </form>
                  </div><!-- /.box -->
                </div><!--/.col (left) -->
                <!-- right column -->
                <div class='col-md-3'>
                    <div class='box box-primary'>
                        <div class='box-body box-profile'>";

                            if(empty($u[logo])){
                                echo"<img class='profile-user-img img-responsive img-circle' src='file/profile/default_user.png' alt='User profile picture'>";
                            }else{
                                echo"<img class='profile-user-img img-responsive img-circle' src='file/profile/$u[logo]' alt='User profile picture'>";
                            }

                          echo"        
                          <h3 class='profile-username text-center'>".$u[nama]."</h3>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
              </div>   <!-- /.row -->
            </section><!-- /.content -->
          </div><!-- /.content-wrapper -->
        ";  
    break;
}
?>



