<?php 
ob_start();
session_start();
error_reporting(0);

$sesi_username    = isset($_SESSION['username']) ? $_SESSION['username'] : NULL;
if ($sesi_username == NULL || empty($sesi_username) )
{
    session_destroy();
    header('Location:login.php?status=Silahkan Login');
}
include "koneksi.php";

$module=$_GET[module];
$act=$_GET[act];


$sql_nilai_l  = mysqli_query($con, "SELECT count(*) as jum FROM tbl_siswa, Pendaftar where Pendaftar.id_Pendaftar=siswa.id_Pendaftar ");
$r_nilai_l    = mysqli_fetch_array($sql_nilai_l);
$siswa=$r_nilai_l['jum'];

?>

<!doctype html>
<html class="no-js" lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Data Tables | Pendaftar</title>
        <meta name="description" content="">
        <meta name="keywords" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        
        <link rel="icon" href="smkadzikri.PNG" type="image/x-icon" />

        <link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800" rel="stylesheet">
        
        <link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
        <link rel="stylesheet" href="node_modules/@fortawesome/fontawesome-free/css/all.min.css">
        <link rel="stylesheet" href="node_modules/ionicons/dist/css/ionicons.min.css">
        <link rel="stylesheet" href="node_modules/icon-kit/dist/css/iconkit.min.css">
        <link rel="stylesheet" href="node_modules/perfect-scrollbar/css/perfect-scrollbar.css">
        <link rel="stylesheet" href="node_modules/datatables.net-bs4/css/dataTables.bootstrap4.min.css">
        <link rel="stylesheet" href="dist/css/theme.min.css">
        <script src="src/js/vendor/modernizr-2.8.3.min.js"></script>
    </head>

    <body>
    <?php include('sidebar.php'); ?>
        <div class="wrapper">

            <div class="page-wrap">
                <div class="main-content">
                    <div class="container-fluid">
                        <div class="page-header">
                            <div class="row align-items-end">
                                <div class="col-lg-8">
                                    <div class="page-header-title">
                                        <i class="ik ik-inbox bg-blue"></i>
                                        <div class="d-inline">
                                            <h5>Data Pendaftar</h5>
                                            <span>Data Pendaftar</span>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-4">
                                    <nav class="breadcrumb-container" aria-label="breadcrumb">
                                        <ol class="breadcrumb">
                                            <li class="breadcrumb-item">
                                                <a href="home.php"><i class="ik ik-home"></i></a>
                                            </li>
                                            <li class="breadcrumb-item">
                                                <a href="#">Tables</a>
                                            </li>
                                            <li class="breadcrumb-item active" aria-current="page">Data Pendaftar</li>
                                        </ol>
                                    </nav>
                                </div>
                            </div>
                        </div>
                         
                        
                        <div class="container col-md-12 mt-6" id="tmb_Pendaftar" tabindex="-1" role="dialog" aria-labelledby="tmb_PendaftarLabel" aria-hidden="true">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-body">
                                        <?php
                                        include('koneksi.php');

                                        $id_pendaftar = $_GET['id_pendaftar']; //mengambil id barang yang ingin diubah

                                        //menampilkan barang berdasarkan id
                                        $data = mysqli_query($con, "select * from pendaftar where id_pendaftar = '$id_pendaftar'");
                                        $row = mysqli_fetch_assoc($data);

                                        ?>
                                        <form action="" method="post" role="form">
                                        <div class="form-group">
                                                <label>NISN</label>
                                                <!--  menampilkan nama barang -->
                                                <input type="text" name="nisn" required="" class="form-control" value="<?= $row['nisn']; ?>">

                                                <!-- ini digunakan untuk menampung id yang ingin diubah -->
                                                <input type="hidden" name="id_pendaftar" required="" value="<?= $row['id_pendaftar']; ?>">
                                            </div>
                                            <div class="form-group">
                                                <label>NIK</label>
                                                <!--  menampilkan nama barang -->
                                                <input type="text" name="nik" required="" class="form-control" value="<?= $row['nik']; ?>">
                                            </div>
                                            <div class="form-group">
                                                <label>Nama</label>
                                                <!--  menampilkan nama barang -->
                                                <input type="text" name="nama" required="" class="form-control" value="<?= $row['nama']; ?>">
                                            </div>
                                            <div class="form-group">
                                                <label>Tempat Lahir</label>
                                                <input type="text" name="t_lahir" class="form-control" value="<?= $row['t_lahir']; ?>">
                                            </div>
                                            <div class="form-group">
                                                <label>Tanggal Lahir</label>
                                                <input type="date" name="tg_lahir" class="form-control" value="<?= $row['tg_lahir']; ?>">
                                            </div>
                                            <div class="form-group">
                                                <label>Jenis Kelamin</label>
                                                <select name="jk" id="jk" value="<?= $row['jk']; ?>" >
                                                <option value="Pilih">Pilih</option>
                                                <option value="Laki-laki">Laki-laki</option>
                                                <option value="Perempuan">Perempuan</option>
                                                </select>
                                            </div>

                                            <div class="form-group">
                                                <label>Alamat</label>
                                                <textarea class="form-control" name="alamat"><?= $row['alamat']; ?></textarea>
                                            </div>
                                            <div class="form-group">
                                                <label>Nomor Hp/Tlpn</label>
                                                <input type="text" name="no_hp" class="form-control" value="<?= $row['no_hp']; ?>">
                                            </div>
                                            <button type="submit" class="btn btn-primary" name="submit" value="simpan">update data</button>
                                        </form>
                                        <?php

                                            //jika klik tombol submit maka akan melakukan perubahan
                                            if (isset($_POST['submit'])) {
                                                $id_pendaftar = $_POST['id_pendaftar'];
                                                $nisn = $_POST['nisn'];
                                                $nik = $_POST['nik'];
                                                $nama = $_POST['nama'];
                                                $t_lahir = $_POST['t_lahir'];
                                                $tg_lahir = $_POST['tg_lahir'];
                                                $jk = $_POST['jk'];
                                                $alamat = $_POST['alamat'];
                                                $no_hp = $_POST['no_hp'];

                                                //query mengubah barang
                                                mysqli_query($con, "update pendaftar set  nisn='$nisn',nik='$nik',nama='$nama',
                                                t_lahir='$t_lahir', tg_lahir='$tg_lahir', jk='$jk', alamat='$alamat',no_hp='$no_hp' where id_pendaftar ='$id_pendaftar'") or die(mysqli_error($koneksi));

                                                //redirect ke halaman index.php
                                                echo "<script>alert('data berhasil diupdate.');window.location='pendaftar.php';</script>";
                                            }



                                            ?>
                                    </div>
                                    
                                </div>
                            </div>
                        </div>                 
                    </div>
                </div>
                <footer class="footer">
                    <div class="w-100 clearfix">
                        <span class="text-center text-sm-left d-md-inline-block">Copyright © 2024 Ujin dzikri v2.0. All Rights Reserved.</span>
                        <span class="float-none float-sm-right mt-1 mt-sm-0 text-center">Crafted with <i class="fa fa-heart text-danger"></i> by <a href="http://lavalite.org/" class="text-dark" target="_blank">Lavalite</a></span>
                    </div>
                </footer>
            </div>
        </div>
        
        
        

        <div class="modal fade apps-modal" id="appsModal" tabindex="-1" role="dialog" aria-labelledby="appsModalLabel" aria-hidden="true" data-backdrop="false">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="ik ik-x-circle"></i></button>
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="quick-search">
                        <div class="container">
                            <div class="row">
                                <div class="col-md-4 ml-auto mr-auto">
                                    <div class="input-wrap">
                                        <input type="text" id="quick-search" class="form-control" placeholder="Search..." />
                                        <i class="ik ik-search"></i>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-body d-flex align-items-center">
                        <div class="container">
                            <div class="apps-wrap">
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-bar-chart-2"></i><span>Dashboard</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-mail"></i><span>Message</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-users"></i><span>Accounts</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-shopping-cart"></i><span>Sales</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-briefcase"></i><span>Purchase</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-server"></i><span>Menus</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-clipboard"></i><span>Pages</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-message-square"></i><span>Chats</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-map-pin"></i><span>Contacts</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-box"></i><span>Blocks</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-calendar"></i><span>Events</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-bell"></i><span>Notifications</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-pie-chart"></i><span>Reports</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-layers"></i><span>Tasks</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-edit"></i><span>Blogs</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-settings"></i><span>Settings</span></a>
                                </div>
                                <div class="app-item">
                                    <a href="#"><i class="ik ik-more-horizontal"></i><span>More</span></a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
        <script>window.jQuery || document.write('<script src="../src/js/vendor/jquery-3.3.1.min.js"><\/script>')</script>
        <script src="../node_modules/popper.js/dist/umd/popper.min.js"></script>
        <script src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
        <script src="../node_modules/perfect-scrollbar/dist/perfect-scrollbar.min.js"></script>
        <script src="../node_modules/screenfull/dist/screenfull.js"></script>
        <script src="../node_modules/datatables.net/js/jquery.dataTables.min.js"></script>
        <script src="../node_modules/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>
        <script src="../dist/js/theme.min.js"></script>
        <script src="../js/datatables.js"></script>
        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
        <script>
            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
            e.src='https://www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
            ga('create','UA-XXXXX-X','auto');ga('send','pageview');
        </script>
    </body>
</html>
