<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>SIDINAR</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../../plugins/fontawesome-free/css/all.min.css">
  <!-- daterange picker -->
  <link rel="stylesheet" href="../../plugins/daterangepicker/daterangepicker.css">
  <!-- iCheck for checkboxes and radio inputs -->
  <link rel="stylesheet" href="../../plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- Bootstrap Color Picker -->
  <link rel="stylesheet" href="../../plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css">
  <!-- Tempusdominus Bootstrap 4 -->
  <link rel="stylesheet" href="../../plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
  <!-- Select2 -->
  <link rel="stylesheet" href="../../plugins/select2/css/select2.min.css">
  <link rel="stylesheet" href="../../plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css">
  <!-- Bootstrap4 Duallistbox -->
  <link rel="stylesheet" href="../../plugins/bootstrap4-duallistbox/bootstrap-duallistbox.min.css">
  <!-- BS Stepper -->
  <link rel="stylesheet" href="../../plugins/bs-stepper/css/bs-stepper.min.css">
  <!-- dropzonejs -->
  <link rel="stylesheet" href="../../plugins/dropzone/min/dropzone.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../../dist/css/adminlte.min.css">
  <!-- summernote -->
  <link rel="stylesheet" href="../../plugins/summernote/summernote-bs4.min.css">

  <link rel="stylesheet" type="text/css" href="../../vendor/datepicker/bootstrap-datepicker.css" />
</head>
<body class="hold-transition sidebar-mini">
<?php
//
include('../../class/Database.php');
$object = new Database;
if(!$object->is_login())
{
    header("location:".$object->base_url);
}
include('menu.php');
// 

$object->query = "SELECT * FROM jenis_naskah WHERE status='enable'";
$result = $object->get_result();
$object->query = "SELECT * FROM kode_klasifikasi ";
$result2 = $object->get_result();
$object->query = "SELECT * FROM tanda_tangan INNER JOIN akun_user,jabatan WHERE tanda_tangan.id_pejabat = akun_user.id_user AND jabatan.id_jabatan=akun_user.id_jabatan";
$result3 = $object->get_result();
$object->query = "SELECT * FROM verifikator INNER JOIN akun_user, jabatan WHERE akun_user.id_user = verifikator.id_pejabat AND jabatan.id_jabatan=akun_user.id_jabatan";
$result4 = $object->get_result();
$object->query = "SELECT * FROM tujuan INNER JOIN akun_user, jabatan WHERE tujuan.id_user_tujuan=akun_user.id_user AND akun_user.id_jabatan = jabatan.id_jabatan";
$result5 = $object->get_result();

//
 if(isset($_POST["myInput"]))
  {
    if($_SESSION['id_akun']==9){
    //upload pdf
    //edit
    $template='';
    $file_pdf='';
    $object->query = "SELECT * FROM surat_keluar WHERE id_surat=".$_POST["myInput"]." ";
    $result = $object->get_result();
    foreach($result as $row)
    {
        $template=$row["template"];
        $file_pdf=$row["file_pdf"];
    }
   ?>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <div class="container-fluid">
          <div class="row mb-2">
            <div class="col-sm-6">
              <h1>Upload PDF</h1>
            </div>
            <div class="col-sm-6">
              <ol class="breadcrumb float-sm-right">
                <li class="breadcrumb-item"><a href="../tables/surat_keluar.php">Home</a></li>
                <li class="breadcrumb-item active">Upload PDF</li>
              </ol>
            </div>
          </div>
        </div><!-- /.container-fluid -->
      </section>

      <!-- Main content -->
      <section class="content">
        <div class="container-fluid">
            <div class="card card-primary">
                <!--div class="card-header">
                  <h3 class="card-title">Upload PDF</h3>
                </div-->
                <!-- /.card-header -->
                <!-- form start -->
                <form id="quickForm" action="../tables/surat_keluar.php" method="post"  enctype="multipart/form-data">
                  <div class="card-body">
                    <div class="form-group" >
                      <iframe src='https://view.officeapps.live.com/op/embed.aspx?src=https://arsiparisbnn.my.id/adminlte/pages/forms/<?=$template?>' width='100%' height='423px' frameborder='0'></iframe>
                    </div>      
                    <?php if($file_pdf==''){ ?>              
                    <div class="form-group" >
                          <label for="exampleInputFile">Masukkan Dokumen (PDF)</label>
                          <div class="input-group">
                            <div class="custom-file">
                            <input type="file" class="custom-file-input" id="customFile" name="customFile">
                            <label class="custom-file-label" for="customFile">Choose file</label>
                            </div>
                          </div>
                      </div>
                  </div>
                  <!-- /.card-body -->
                  
                  <div class="card-footer">
                    <input type="hidden" name="template" id="template" value="<?=$template?>" />
                    <input type="hidden" name="hidden_id" id="hidden_id" value="<?=$_POST["myInput"]?>" />
                    <input type="hidden" name="action" id="action" value="upload_pdf" />
                    <button type="submit" class="btn btn-primary">Update</button>
                  </div>
                  <?php 
                        
                    }else echo '<div class="form-group" ><a href="https://arsiparisbnn.my.id/adminlte/pages/forms/'.$file_pdf.'" class="nav-link">Download PDF</a></div>';
                  
                  ?>
                </form>
              </div>
          <!-- /.row -->
        </div>
        <!-- /.container-fluid -->
      </section>
      <!-- /.content -->
    </div>
    <?php
    } else {
    //
    $object->query = "SELECT * FROM surat_keluar WHERE id_surat=".$_POST["myInput"];
    $result8 = $object->get_result();
    foreach($result8 as $row)
    {
        $status=$row["status"];
    }
    if($status==4){
    //
    $template='';
    $file_pdf='';
    $object->query = "SELECT * FROM surat_keluar WHERE id_surat=".$_POST["myInput"]." ";
    $result = $object->get_result();
    foreach($result as $row)
    {
        $template=$row["template"];
        $file_pdf=$row["file_pdf"];
    }
        ?>
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <div class="container-fluid">
          <div class="row mb-2">
            <div class="col-sm-6">
              <h1>Upload PDF</h1>
            </div>
            <div class="col-sm-6">
              <ol class="breadcrumb float-sm-right">
                <li class="breadcrumb-item"><a href="../tables/surat_keluar.php">Home</a></li>
                <li class="breadcrumb-item active">Upload PDF</li>
              </ol>
            </div>
          </div>
        </div><!-- /.container-fluid -->
      </section>

      <!-- Main content -->
      <section class="content">
        <div class="container-fluid">
            <div class="card card-primary">
                <!--div class="card-header">
                  <h3 class="card-title">Upload PDF</h3>
                </div-->
                <!-- /.card-header -->
                <!-- form start -->
                <form id="quickForm" action="../tables/surat_keluar.php" method="post"  enctype="multipart/form-data">
                  <div class="card-body">
                    <div class="form-group" >
                      <iframe src='https://view.officeapps.live.com/op/embed.aspx?src=https://arsiparisbnn.my.id/adminlte/pages/forms/<?=$template?>' width='100%' height='423px' frameborder='0'></iframe>
                    </div>               
                  </div>
                  <!-- /.card-body -->
                  <div class="form-group" ><a href="https://arsiparisbnn.my.id/adminlte/pages/forms/<?=$file_pdf?>" class="nav-link">Download PDF</a></div>
                </form>
              </div>
          <!-- /.row -->
        </div>
        <!-- /.container-fluid -->
      </section>
      <!-- /.content -->
    </div>
    <?php
    }
    else {
    //edit
    $kode_klasifikasi='';
    $kode_ttd='';
    $jenis_naskah='';
    $perihal='';
    $tanggal='';
    $status='';
    $verifikator = array();
    $object->query = "SELECT *,verifikator_detail.id_verifikator as verifikator, surat_keluar.status as status_ FROM verifikator_detail INNER JOIN akun_user,surat_keluar,tanda_tangan WHERE akun_user.id_user = verifikator_detail.id_verifikator AND verifikator_detail.id_surat = surat_keluar.no_urut AND surat_keluar.ttd = tanda_tangan.id_pejabat AND surat_keluar.id_surat=".$_POST["myInput"]." ";
    $result6 = $object->get_result();
    foreach($result6 as $row)
    {
        $jenis_naskah=$row["jenis_naskah"];
        $kode_klasifikasi=$row["klasifikasi"];
        $kode_ttd=$row["kode_ttd"];
        $perihal=$row["perihal"];
        $tanggal=$row["tanggal"];
        $verifikator[] = $row["verifikator"];
        $status=$row["status_"];
    }
    //
    $tujuan = array();
    //
    $object->query ="SELECT * FROM tujuan_detail INNER JOIN tujuan, akun_user, surat_keluar WHERE tujuan_detail.id_tujuan = tujuan.id_user_tujuan AND akun_user.id_user = tujuan_detail.id_tujuan AND tujuan_detail.id_surat = surat_keluar.no_urut AND surat_keluar.id_surat=".$_POST["myInput"]." ";
    $result7 = $object->get_result();
    foreach($result7 as $row)
    {
        $tujuan[]=$row["id_user_tujuan"];
    }
   ?>
  <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <div class="container-fluid">
          <div class="row mb-2">
            <div class="col-sm-6">
              <h1>Edit Surat Keluar</h1>
            </div>
            <div class="col-sm-6">
              <ol class="breadcrumb float-sm-right">
                <li class="breadcrumb-item"><a href="../tables/surat_keluar.php">Home</a></li>
                <li class="breadcrumb-item active">Edit Surat Keluar</li>
              </ol>
            </div>
          </div>
        </div><!-- /.container-fluid -->
      </section>

      <!-- Main content -->
      <section class="content">
        <div class="container-fluid">

            <div class="card card-primary">
                <!--div class="card-header">
                  <h3 class="card-title">Surat Keluar</h3>
                </div-->
                <!-- /.card-header -->
                <!-- form start -->
                <form id="quickForm" action="../tables/surat_keluar.php" method="post"  enctype="multipart/form-data">
                  <div class="card-body">
                  <div class="row">
                  <div class="col-md-6">
                    <div class="form-group">
                      <label>Jenis Naskah</label>
                      <select class="form-control select2" name="jenis_naskah" style="width: 100%;" required>
                        <option value="">Pilih Jenis naskah</option>
                        <?php foreach($result as $row)
                          {
                            if ($row["kode_naskah"]==$jenis_naskah) {
                              //$kode_ttd = $row["kode_ttd"];
                              echo '<option value="'.$row["kode_naskah"].'" selected="selected">'.$row["jenis_naskah"].'</option>';
                            }else  echo '<option value="'.$row["kode_naskah"].'">'.$row["jenis_naskah"].'</option>';
                          }
                        ?>
                      </select>
                    </div>
                  </div>
                  <div class="col-md-6">
                  <div class="form-group">
                    <label>Kode Klasifikasi</label>
                    <select class="form-control select2" name="kode_klasifikasi" style="width: 100%;" required>
                      <option value="">Pilih Klasifikasi</option>
                      <?php foreach($result2 as $row)
                        {
                          if ($row["kode_klasifikasi"]==$kode_klasifikasi) {
                              //$kode_ttd = $row["kode_ttd"];
                              echo '<option value="'.$row["kode_klasifikasi"].'" selected="selected">'.$row["kode_klasifikasi"].' '.$row["nama_klasifikasi"].'</option>';
                            }else  echo '<option value="'.$row["kode_klasifikasi"].'">'.$row["kode_klasifikasi"].' '.$row["nama_klasifikasi"].'</option>';
                        }
                      ?>
                    </select>
                  </div>
                </div>
              </div>

              <div class="row">
                <div class="col-md-6">
                  <div class="form-group">
                    <label>Tanggal</label>
                      <input type="text" name="tanggal" id="tanggal" class="form-control datepicker" value="<?=$tanggal?>" data-parsley-trigger="keyup" readonly />
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="form-group">
                    <label>Penanda Tangan</label>
                    <select class="form-control select2" name="tanda_tangan" style="width: 100%;" required>
                      <option value="">Pilih Penanda Tangan</option>
                        <?php foreach($result3 as $row)
                        {
                          if ($row["kode_ttd"]==$kode_ttd) {
                              //$kode_ttd = $row["kode_ttd"];
                              echo '<option value="'.$row["id_pejabat"].'" selected="selected">'.$row["nama"].' - '.$row["nama_jabatan"].'</option>';
                            }
                          else  echo '<option value="'.$row["id_pejabat"].'">'.$row["nama"].' - '.$row["nama_jabatan"].'</option>';
                        }
                        ?>
                    </select>
                  </div>
                </div>
              </div>
              <div class="form-group" >
                  <label>Perihal</label>
                  <textarea id="inputDescription" name="perihal" class="form-control" rows="4" ><?=$perihal?>
                  </textarea>
              </div>
                    
              <div class="row">
                <div class="col-md-6">
                  <div class="form-group">
                  <table id="example1" class="table table-bordered table-hover">
                    <thead>
                    <tr>
                      <th>Tujuan</th>
                      <th>Jabatan</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                      $object->query = "SELECT * FROM tujuan_detail INNER JOIN surat_keluar, akun_user, jabatan WHERE tujuan_detail.id_surat = surat_keluar.no_urut AND akun_user.id_user = tujuan_detail.id_tujuan AND jabatan.id_jabatan=akun_user.id_jabatan  AND surat_keluar.id_surat= ".$_POST["myInput"]." ORDER BY id_detail ASC";
                      $result = $object->get_result();
                      foreach($result as $row)
                      {
                        echo '<tr><td>'.$row["nama"].'</td>';
                        echo '<td>'.$row["nama_jabatan"].'</td>';
                      }
                    ?>
                    </tbody>
                  </table>
                </div>
                </div>
                <div class="col-md-6">
                  <div class="form-group">
                    <table id="example1" class="table table-bordered table-hover">
                      <thead>
                      <tr>
                        <th>Verifikator</th>
                        <th>Jabatan</th>
                      </tr>
                      </thead>
                      <tbody>
                      <?php
                        $object->query = "SELECT * FROM verifikator_detail INNER JOIN surat_keluar, akun_user, jabatan WHERE verifikator_detail.id_surat = surat_keluar.no_urut AND akun_user.id_user = verifikator_detail.id_verifikator AND jabatan.id_jabatan=akun_user.id_jabatan  AND surat_keluar.id_surat= ".$_POST["myInput"]." ORDER BY id_detail ASC";
                        $result = $object->get_result();
                        foreach($result as $row)
                        {
                          echo '<tr><td>'.$row["nama"].'</td>';
                          echo '<td>'.$row["nama_jabatan"].'</td>';
                        }
                      ?>
                      </tbody>
                  </table>
                  </div>
                </div>
              </div>
                    <div class="form-group">
                      <label for="exampleInputFile">Masukkan Dokumen (docx)</label>
                      <div class="input-group">
                        <div class="custom-file">
                        <input type="file" class="custom-file-input" id="customFile" name="customFile">
                        <label class="custom-file-label" for="customFile">Choose file</label>
                      </div>
                      </div>
                    </div>

                  </div>
                  <?php 
                    if ($status==0){
                  ?>
                  <!-- /.card-body -->
                  <div class="card-footer">
                    <input type="hidden" name="hidden_id" id="hidden_id" value="<?=$_POST["myInput"]?>" />
                    <input type="hidden" name="action" id="action" value="edit_surat" />
                    <button type="submit" class="btn btn-primary">Update</button>
                  </div>
                  <?php
                  }
                  ?>
                </form>
              </div>
          <!-- /.row -->
        </div>
        <!-- /.container-fluid -->
      </section>
      <!-- /.content -->
    </div>
<?php
    }
  }
  } else{
?>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Tambah Surat Keluar</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="../tables/surat_keluar.php">Home</a></li>
              <li class="breadcrumb-item active">Tambah Surat Keluar</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">

          <div class="card card-primary">
              <!--div class="card-header">
                <h3 class="card-title">Surat Keluar</h3>
              </div-->
              <!-- /.card-header -->
              <!-- form start -->
              <form id="quickForm" action="../tables/surat_keluar.php" method="post">
                <div class="card-body">
                <div class="row">
                <div class="col-md-6">
                  <div class="form-group">
                  <label>Jenis Naskah</label>
                  <select class="form-control select2" name="jenis_naskah" style="width: 100%;" required>
                    <option value="">Pilih Jenis naskah</option>
                    <?php foreach($result as $row)
                      {
                        echo '<option value="'.$row["kode_naskah"].'">'.$row["jenis_naskah"].'</option>';
                      }
                    ?>
                  </select>
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label>Kode Klasifikasi</label>
                  <select class="form-control select2" name="kode_klasifikasi" style="width: 100%;" required>
                    <option value="">Pilih Klasifikasi</option>
                    <?php foreach($result2 as $row)
                      {
                        echo '<option value="'.$row["kode_klasifikasi"].'">'.$row["kode_klasifikasi"].' '.$row["nama_klasifikasi"].'</option>';
                      }
                    ?>
                  </select>
                </div>
              </div>
            </div>
              <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label>Tanggal</label>
                    <input type="text" name="tanggal" id="tanggal" class="form-control datepicker" data-parsley-trigger="keyup" readonly />
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label>Penanda Tangan</label>
                  <select class="form-control select2" name="tanda_tangan" style="width: 100%;" required>
                    <option value="">Pilih Penanda Tangan</option>
                      <?php foreach($result3 as $row)
                      {
                        echo '<option value="'.$row["id_pejabat"].'">'.$row["nama"].' - '.$row["nama_jabatan"].'</option>';
                      }
                      ?>
                  </select>
                </div>
              </div>
            </div>
                <div class="form-group" >
                  <label>Perihal</label>
                  <textarea id="inputDescription" name="perihal" class="form-control" rows="4">
                  </textarea>
                </div>
            <div class="row">
              <div class="col-md-6">
                <div class="form-group">
                  <label>Tujuan</label>
                  <select class="select2" multiple="multiple" name="tujuan[]" required style="width: 100%;">
                    
                    <?php foreach($result5 as $row)
                      {
                        echo '<option value="'.$row["id_user"].'">'.$row["nama"].' '.$row["nama_jabatan"].'</option>';
                      }
                    ?>
                  </select>
                </div>
              </div>
              <div class="col-md-6">
                <div class="form-group">
                  <label>Verifikator</label>
                  <select class="select2" multiple="multiple" name="verifikator[]" required style="width: 100%;">
                    
                    <?php foreach($result4 as $row)
                      {
                        echo '<option value="'.$row["id_user"].'">'.$row["nama"].' '.$row["nama_jabatan"].'</option>';
                      }
                    ?>
                  </select>
                </div>
              </div>
                </div>
                <!-- /.card-body -->
                <div class="card-footer">
                  <input type="hidden" name="action" id="action" value="add_surat" />
                  <button type="submit" class="btn btn-primary">Submit</button>
                </div>
              </form>
            </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
<?php 
}
?>

  <!-- /.content-wrapper -->
  <footer class="main-footer">
    <div class="float-right d-none d-sm-block">
      <b>Version</b> 3.2.0
    </div>
    <strong>Copyright &copy; 2014-2021 <a href="https://adminlte.io">AdminLTE.io</a>.</strong> All rights reserved.
  </footer>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="../../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Select2 -->
<script src="../../plugins/select2/js/select2.full.min.js"></script>
<!-- Bootstrap4 Duallistbox -->
<script src="../../plugins/bootstrap4-duallistbox/jquery.bootstrap-duallistbox.min.js"></script>
<!-- InputMask -->
<script src="../../plugins/moment/moment.min.js"></script>
<script src="../../plugins/inputmask/jquery.inputmask.min.js"></script>
<!-- date-range-picker -->
<script src="../../plugins/daterangepicker/daterangepicker.js"></script>
<!-- bootstrap color picker -->
<script src="../../plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="../../plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Bootstrap Switch -->
<script src="../../plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<!-- BS-Stepper -->
<script src="../../plugins/bs-stepper/js/bs-stepper.min.js"></script>
<!-- dropzonejs -->
<script src="../../plugins/dropzone/min/dropzone.min.js"></script>
<!-- AdminLTE App -->
<script src="../../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
<!-- Summernote -->
<script src="../../plugins/summernote/summernote-bs4.min.js"></script>

<script src="../../vendor/datepicker/bootstrap-datepicker.js"></script>
<!-- bs-custom-file-input -->
<script src="../../plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- Page specific script -->
<script>
  $(function () {
    //
    bsCustomFileInput.init();
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })

    //Datemask dd/mm/yyyy
    $('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
    //Datemask2 mm/dd/yyyy
    $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
    //Money Euro
    $('[data-mask]').inputmask()

    //Date picker
    $('#reservationdate').datetimepicker({
        format: 'L'
    });

    $('#tanggal').datepicker({
        format: "yyyy-mm-dd",
        autoclose: true
    });

  })
  // BS-Stepper Init
  document.addEventListener('DOMContentLoaded', function () {
    window.stepper = new Stepper(document.querySelector('.bs-stepper'))
  })
</script>
</body>
</html>
