<?php
include "db.php";

if(!empty($_POST))
{
    $conn = connect_db();
    
    $list_nilai = get_nilai_by_ID($conn, $_POST['npm']);
    $person = get_data_person($conn, $_POST['npm']);
    
    //echo "<pre>";
    //print_r($person);
    //while($row = $list_nilai->fetch_assoc())
    //{
    //    print_r($row);
    //}
    //echo "</pre>";
}
?>
<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Language" content="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>eSertifikat - UPT Bahasa Universitas Lampung</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no"
    />
    <meta name="description" content="ArchitectUI HTML Bootstrap 4 Dashboard Template">

    <!-- Disable tap highlight on IE -->
    <meta name="msapplication-tap-highlight" content="no">

<link href="main.css" rel="stylesheet">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-130022200-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-130022200-1');
</script>
</head>

<style>

th, td {
    text-align: center
}

</style>

<body>
<div class="app-container app-theme-white body-tabs-shadow">
        <div class="app-container">
            <div class="h-100 bg-plum-plate bg-animation">
                <div class="d-flex h-100 justify-content-center align-items-center">
                    <div class="mx-auto app-login-box col-md-8">
                        <!--<div class="app-logo-inverse mx-auto mb-3"></div> -->
                        <center><img src="assets/images/logo_unila.png" style="height: 150px;"/></center>
                        <div class="modal-dialog w-100 mx-auto">
                            
                            <div class="modal-content">
                                <div class="modal-header">
                                <?php
                                if(!empty($_POST))
                                {
                                    if(empty($person['ID']))
                                    {
                                        echo "Data tidak ditemukan";
                                    }
                                    else
                                    {
                                        echo $person['ID']." - ".$person['nama'];
                                    }
                                }
                                else
                                {
                                    echo "eSertifikat UPT Bahasa Universitas Lampung";
                                }
                                ?>
                                </div>
                                <div class="modal-body" <?php if(!empty($_POST)) echo 'style="padding: 0"' ?>)>
                                    
                                    <?php
                                    if(!empty($_POST)) 
                                    {
                                        if($list_nilai->num_rows > 0)
                                        {

                                       ?>
                                       <div class="table-responsive">
<table class="mb-0 table table-striped table-hover">
                                        <thead>
                                        <tr>
                                            <th style="width: 20%">Tes ke-</th>
                                            <th  style="width: 30%">Tgl Tes</th>
                                            <th  style="width: 30%">Skor</th>
                                            <th  style="width: 20%">Sertifikat</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php
                                        while($row = $list_nilai->fetch_assoc())
                                        {
                                            $tgl_tes = date_format(date_create($row['tes_tgl']), "d/m/Y");
                                            $path_download = "download/sertifikat/";
                                            if($row['kategori'] == 'kursus') {
                                                $path_download .= "sertifikat1.php";
                                            }
                                            else
                                            {
                                                $path_download .= "sertifikat2.php";
                                            }
                                        ?>
                                        <tr>
                                            <td><?php echo $row['tes_ke'] ?></td>
                                            <td><?php echo $tgl_tes ?></td>
                                            <td><strong><?php echo $row['skor'] ?></strong></td>
                                            <td><a href="<?php echo $path_download."?id=".$row['user_ID']."&tgl=".$row['tes_tgl'] ?>" class="btn-shadow">
                                            <span class="btn-icon-wrapper">
                                                <i class="fas fa-file-pdf"></i> Unduh
                                            </span>
                                    </a></td>
                                        </tr>
                                        <?php
                                        }
                                        ?>
                                        
                                        </tbody>
                                    </table>
</div>
                                       <?php
                                        }
                                        else
                                        {
?>
<div class="alert alert-danger fade show" role="alert">Mohon maaf, data tidak ditemukan!</div>
<?php
                                        }
                                    }
                                    else
                                    {
                                    ?>
                                    <form id="login-form" class="" method="post" action="">
                                        
                                        <div class="form-row">
                                            <div class="col-md-12">
                                                <div class="position-relative form-group"><input required name="npm" id="username" placeholder="Masukan NPM Anda untuk mengunduh..." type="text" class="form-control"></div>
                                            </div>
                                            
                                        </div>
                                    </form>
                                    
                                    <div class="alert alert-info fade show" role="alert">*berlaku mulai 1 April 2020<br>
                                    Cetak Sertifikat:<br>
                                    - Kertas A4 Putih (Kursus)<br>
                                    - Kertas F4 Putih dibagi 2 (Reguler)<br>
                                    - <b>Jenis Kertas Concorde</b></div>
                                    <?php 
                                    }
                                    ?>
                                    
                                </div>
                                <div class="modal-footer clearfix">
                                    <div class="float-left"></div>
                                    <div class="float-right">
                                    <?php
                                    if(empty($_POST))
                                    {

                                    ?>
                                        <button type="submit" form="login-form" class="btn btn-primary btn-lg"><span class="btn-icon-wrapper pr-2 opacity-7">
                                                <i class="fas fa-search fa-w-20"></i>
                                            </span> Cek Sertifikat TOEFL</button>
                                        <?php
                                    }
                                    else 
                                    {
                                        ?>
                                    <a href="javascript:history.back()" class="btn-shadow btn btn-success">
                                            <span class="btn-icon-wrapper pr-2 opacity-7">
                                                <i class="fas fa-arrow-left fa-w-20"></i>
                                            </span>
                                            Cari Kembali
                                    </a>
                                    <?php
                                    }

                                    ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="text-center text-white opacity-8 mt-3">Copyright © 2020 UPT Bahasa Universitas Lampung | All Rights Reserved.<br>Template by ArchitectUI 2019</div>
                    </div>
                </div>
            </div>
        </div>
</div>
<script type="text/javascript" src="assets/scripts/main.js"></script>
</body>
</html>
